Foreground example Code The following figure shows how to use the datalist control to display studentid and name in the student table.
Copy code The Code is as follows: <asp: datalist id = "dltable" runat = "server">
<Itemtemplate>
<TD align = "center">
<Asp: Label id = "lblid" runat = "server" text = '<% # eval ("studentid") %> 'visible = "false"> </ASP: label>
<Asp: checkbox id = "chkbox" runat = "server"/>
</TD>
<TD>
<% # Eval ("studentname") %>
</TD>
<TD>
<% # Eval ("studentid") %>
</TD>
</Itemtemplate>
</ASP: datalist>
The background code is as follows:Copy codeThe Code is as follows: // new stringbulider instance sbitems
Stringbuilder sbitems = new stringbuilder ();
Foreach (datalistitem item in dltable. Items)
{
// Obtain the foreground Control
Checkbox chkbox = item. findcontrol ("chkbox") as checkbox;
Label LBID = item. findcontrol ("lblid") as label;
// If the checkbox is checked, assign the value bound to the corresponding label to sbitems for subsequent operations, such as deletion.
If (chkbox = NULL | lblid = NULL)
{
Continue;
}
If (chkbox. Checked)
{
Sbitems. append (lblid. Text. tostring ());
Sbitems. append (",");
}
}
// Remove the comma because a comma is added.
If (! Sbitems. tostring (). Trim (). Equals (string. Empty ))
{
Sbitems. Remove (sbitems. Length-1, 1 );
}
in this way, the value selected in the front-end checkbox is obtained, but I feel that this method is a little more complicated. If you can better use C # To obtain the checkbox value, please kindly advise. I 'd like to know how to use the checkboxlist method.