Showing posts with label checkboxlist. Show all posts
Showing posts with label checkboxlist. Show all posts

Thursday, July 1, 2010

Check All Checkboxes in GridView using JQuery

ASPX:

<asp:GridView ID="gridContacts" runat="server" >
<Columns >
<asp:TemplateField >

<HeaderTemplate ><asp:CheckBox ID="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" / ></HeaderTemplate >

<ItemTemplate ><asp:CheckBox ID="chkDelete" runat="server" / ></ItemTemplate >

</asp:TemplateField >

<asp:BoundField DataField="FirstName" HeaderText="First Name" / >

</Columns >
</asp:GridView
>


Javascript:

function SelectAllCheckboxes(cb) {

$('#gridContacts > tbody > tr > td > input:checkbox').attr('checked', cb.checked);
}


Additional reading:

Check All Checkboxes with Jquery

Sunday, July 5, 2009

CheckBoxList in ASP.NET

To retrieve the input information from a check box list, traverse through all the items in the list and determine if the value is set to true (i.e. selected).

C# Code:
protected void btnSubmit_Click(object sender, EventArgs e) {
  
    label1.Text = "You selected: ";
    foreach (ListItem li in checkBoxList.Items) {
      if (li.Selected == true) label1.Text += li.Text + " ";
    }
}