About the data row in the loop gridview and repeater!

Source: Internet
Author: User
Nested repeater in the gridview displays hierarchical data:

In the gridview1_databound event of gridview1, write as follows:

  Protected   Void Gridviewdomaindatabound ( Object Sender, eventargs E)
{
Foreach (Gridviewrow row In Gridview1.rows)
{
Label labelid = Row. findcontrol ( " Label1 " ) As Label;
String Parentid = Labelid. Text. tostring ();
Repeater subrepeater = Row. findcontrol ( " Repeater1 " ) As Repeater;
String SQL =   " Select * From candidateuser where wantposition =' " + Parentid + " 'Order by uid ASC " ;
Dataset DS = Newdb. commondataset (SQL );
Subrepeater. datasource = DS. Tables [ 0 ]. Defaultview;
Subrepeater. databind ();

}

}

Then, when you click the button to submit this page, you need to loop through the data values in gridview1 and repeater1 and save them to the database. How can you set the values: Protected   Void Button#click ( Object Sender, eventargs E)
{
Foreach (Gridviewrow row In Gridview1.rows)
{
Label labelid = Row. findcontrol ( " Label1 " ) As Label; // Id label of the competitive position
Parentid = Labelid. Text. tostring (); // ID of the competitive position

Repeater subrepeater=Row. findcontrol ("Repeater1")AsRepeater;

Foreach (Repeateritem subrow In Subrepeater. Items)
{
Label labeluserid = Subrow. findcontrol ( " Label2 " ) As Label; // Id label of the competitor
Candidateuserid = Labeluserid. Text. tostring (); // ID of the competitor

Textbox txbscore = Subrow. findcontrol ( " Textbox1 " ) As Textbox; // Score textbox1
Candidatescore = Txbscore. Text. tostring (); // Score

Checkbox ckbgiveup = Subrow. findcontrol ( " Checkbox1 " ) As Checkbox; // Score textbox1
If (Ckbgiveup. Checked =   True )
{
Giveup =   " 1 " ;
}
Else
{
Giveup =   " 0 " ;
}

SQL =   " Insert into votetable (positionid, candidateuserid, candidateuserscore, giveupvote, whosendthevote) values (' "   + Parentid +   " ',' "   + Candidateuserid +   " ',' "   + Candidatescore +   " ',' "   + Giveup +   " ',' "   + Getname +   " ') " ;
Newdb. modifydata (SQL );

}

}

 
 

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.