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 );
}
}
}