I have a WebDataGrid and an UnboundCheckBoxField column. I want to be able to check and uncheck the check box in the header from the code behind, thereby selecting or unselecting all the items. There is WebDataGrid1.Columns["IsActive"].Header but there is no value there I can set.
Your approach is correct, just cast the column to UnboundCheckBoxField
and use HeaderChecked
property.
Code snippet (C#):
protected void button1_Click(object sender, EventArgs e)
{
UnboundCheckBoxField checkboxField = (WebDataGrid1.Columns[0] as UnboundCheckBoxField);
checkboxField.HeaderChecked = !checkboxField.HeaderChecked;
}
Code snippet (aspx):
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<ig:UnboundCheckBoxField Key="Check" HeaderChecked="true" Width="25px" />
...
</Columns>
<Behaviors>
<ig:EditingCore>
<Behaviors>
<ig:CellEditing>
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
</Behaviors>
Gif: