This gets the value selected in the Foreground checkbox, but I feel like this method is a little bit more complicated, you guys. If there is a better way to get a checkbox through C #, please enlighten me. I am very interested to know how to use the CheckBoxList method.
New instance of a Stringbulider Sbitems
StringBuilder sbitems = new StringBuilder ();
foreach (DataListItem item in Dltable.items)
{
Get foreground control
CheckBox Chkbox = Item. FindControl ("Chkbox") as CheckBox;
Label lbid = Item. FindControl ("Lblid") as Label;
If the checkbox is check, assign the value of the corresponding label binding to Sbitems for subsequent operations, such as deletion.
if (Chkbox = null | | lblid== null)
{
Continue
}
if (Chkbox. Checked)
{
Sbitems. Append (LblID.Text.ToString ());
Sbitems. Append (",");
}
}
Because I have a comma, I want to remove the comma.
if (!sbitems. ToString (). Trim (). Equals (String. Empty))
{
Sbitems. Remove (Sbitems. Length-1, 1);
}
<asp Tutorial: 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> br> </asp:datalist>