Monday, April 22, 2013

how to get selected items from checkboxlist in c#

In previous post i have given how to get the id of checkbox using jqury ,check all checkbox in gridview.In this post i will show how to get the selected values of check box list in below piece of code i have looping thorough the check box list items on button click event .Then the resultant value has assigned to string
<asp:CheckBoxList ID="ChkOrdrList" runat="server">
<asp:Button ID="btngetOrdr" Text="Ok" OnClick="btlgetOrder_Click" runat="server" />
<asp:TextBox ID="txtOrdername" runat="server" />

public void btlgetOrder_Click(object Source, EventArgs e)
String strOrdr = "Checkboxlist selected Item is:";
for (int i = 0; i < ChkOrdrList.Items.Count; i++)
if (ChkOrdrList.Items[i].Selected)
strOrdr = strOrdr +","+ ChkOrdrList.Items[i].Text;
txtOrdername.Text = strOrdr;
Post a Comment