Checkbox in Gridview Header
I wnat to have checkbox in Gridview Header. On the checkbox changed I wnat to check and uncheck all the checkboxes of the Gridview Rows. Currently I am doing it on the button click. But I want to have checkbox in Gridview header, How to have checkbox in Gridview Header,can somebody tell me??
Code:
protected void btnCheckAll_Click(object sender, EventArgs e)
{
Check_Uncheck_Checkboxes(true);
}
protected void btnunCheckAll_Click(object sender, EventArgs e)
{
Check_Uncheck_Checkboxes(false);
}
private void Check_Uncheck_Checkboxes(bool bState)
{
CheckBox chk;
foreach (GridViewRow rowItem in GrdCompanies.Rows)
{
chk = (CheckBox)(rowItem.Cells[1].FindControl("chkSelect"));
chk.Checked = bState;
}
}
Re: Checkbox in Gridview Header
Hey,
You could do this work in the RowCreated event of the GridView.
http://msdn.microsoft.com/en-us/libr...owcreated.aspx
Check to see if the RowType is the Header, and if it is, add the necessary controls, and hook up the event handles.
Either that, or edit the HeaderTemplate for the column that you are interested in.
Gary
Re: Checkbox in Gridview Header
hay,
you can use the HeaderTemplate
Code:
<asp:GridView ID="GridView2" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Header " />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>