Home > ASP.Net, Javascript > Select All CheckBoxes in Repeater Control

Select All CheckBoxes in Repeater Control


Hi all,

try this example to select all checkbox in Repeater control when i check a CheckBox in header


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title></title>
 <script type="text/javascript">
 function checkAll(cb) {
 var ctrls = document.getElementsByTagName('input');
 for (var i = 0; i < ctrls.length; i++) {
 var cbox = ctrls[i];
 if (cbox.type == "checkbox") {
 cbox.checked = cb.checked;
 }
 }
 }
 </script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
 <HeaderTemplate>
 <table style="width: 60%; margin: 2px;">
 <tr style="background-color: Gray;">
 <th>
 <asp:CheckBox ID="cbCheckAll" runat="server" Text="Select All" OnClick="checkAll(this)" />
 </th>
 <th>
 Category Name
 </th>
 <th>
 Description
 </th>
 </tr>
 </HeaderTemplate>
 <ItemTemplate>
 <tr>
 <td>
 <asp:CheckBox ID="chk" runat="server" />
 </td>
 <td>
 <asp:Label ID="lbl_Name" runat="server" Text='<%#Eval("CategoryName")%>'></asp:Label>
 </td>
 <td>
 <asp:Label ID="lbl_Description" runat="server" Text='<%#Eval("Description")%>'></asp:Label>
 </td>
 </tr>
 </ItemTemplate>
 </asp:Repeater>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
 SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
 </asp:SqlDataSource>
 </div>
 </form>
</body>
</html>

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. anonymous
    June 27, 2012 at 11:21 am

    excellent thankyou

  2. July 3, 2013 at 9:16 am

    thanksss a tonnn

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: