Hi all, here in this asp.net tutorials we will learn to count how many item selected on checkboxlist control in ASP.Net.
– We all are aware of CheckBoxList control in ASP.Net. So, we all know how to select item on CheckBoxList Control, Here we just learn to count that Select Item of CheckBoxList control in ASP.Net with an Example.
STEP 1 – First Design the ASP.Net webpage with one CheckBoxList Control, one Button Control and one Label Control for dispaly the result of Example.
– The HTML Design code for ASP.Net Example is:
<table style=”width: 464px”>
<tr>
<td colspan=”1″ style=”width: 257px; height: 24px”>
<strong><span style=”font-size: 14pt; color: #6600cc; font-family: Arial”>Count Selected
Item – CheckBoxList</span></strong></td>
</tr>
<tr>
<td style=”width: 257px; height: 24px; text-align: center;”>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Count Selected” Font-Bold=”True” Font-Size=”Medium” /> </td>
</tr>
<tr>
<td style=”width: 257px; height: 22px; text-align: center;”>
<asp:CheckBoxList ID=”CheckBoxList1″ runat=”server” Width=”168px”>
</asp:CheckBoxList>
<asp:Label ID=”Label1″ runat=”server”></asp:Label></td>
</tr>
<tr>
<td style=”width: 257px; height: 22px; text-align: center”>
</td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>
– The ASP.Net Example of CheckBoxList Selected Item Count design output is:
STEP 2 – Write the below code at code behing page of ASP.Net webform.
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{string[] Days = { “Sunday”, “Monday”, “Tusday”, “Wednesday”, “Thursday” };
CheckBoxList1.DataSource = Days;
CheckBoxList1.DataBind();
}
}protected void Button1_Click(object sender, EventArgs e)
{
int count=0;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
count=count+ 1;
}
}
Label1.Text =”Selectd Item = “+ count.ToString();
}
– The ASP.Net Example of CheckBoxList Selected Item Count output is:
– The above asp.net result display the Three items selected on checkboxlist control in asp.net.
– This ASP.Net Example of CheckBoxList Control Selected Item Count will help you……