asp.net gets the value program for the DataList checkbox

Source: Internet
Author: User

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>

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.