HTML Markup
Step 1: Select CheckBox
- <asp:Label ID="Label1" runat="server" Text="Label">Select All</asp:Label>
- <asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="true" OnCheckedChanged="CheckAll" />
Step 2: Select DataList and use another CheckBox control for checking all checkboxes.
- <asp:DataList ID="dlforms" runat="server" RepeatColumns="6" Width="1800px">
- <ItemTemplate>
- <table>
- <tr>
- <td>
- <asp:Label ID="lblformid" Visible="false" runat="server" Text='<%#Eval("Form_id")%>'></asp:Label>
- <asp:CheckBox ID="chkRow" runat="server" Font-Bold="true" Text='<%#Eval("Form_name")%>'
- </tr>
- </table>
- </ItemTemplate>
- </asp:DataList>
C#
Step 3: Fill DataList from DataBase.
- protected void Page_Load(object sender, EventArgs e)
- {
- if(!IsPostBack)
- {
- Fill_grid();
- }
- }
- protected void Fill_grid()
- {
- string dt = "select * from tbl_frm";
- DataTable dr = c1.filldt(dt);
- dlforms.DataSource = dr;
- dlforms.DataBind();
- }
Step 4: OnCheckedChanged="CheckAll" Event Code.
- protected void CheckAll(object sender, EventArgs e)
- {
- CheckBox btnComplain = sender as CheckBox;
- if(btnComplain.Checked == true)
- {
- foreach(DataListItem grd in dlforms.Items)
- {
- CheckBox chb = (CheckBox) dlforms.Items[grd.ItemIndex].FindControl("chkRow");
- chb.Checked = true;
- }
- }
- else
- {
- foreach(DataListItem grd in dlforms.Items)
- {
- CheckBox chb = (CheckBox) dlforms.Items[grd.ItemIndex].FindControl("chkRow");
- chb.Checked = false;
- }
- }
- }
Step 5: OnCheckedChanged="check" Event Code.
- protected void check(object sender, EventArgs e)
- {
-
- }