如何在C#中取消选中WebDataGrid中的标题复选框

问题描述 投票:2回答:1

我有一个WebDataGrid和一个UnboundCheckBoxField列。我希望能够检查并取消选中后面代码中标题中的复选框,从而选择或取消选择所有项目。有WebDataGrid1.Columns [“IsActive”]。标题,但我没有设置值。

asp.net infragistics webdatagrid
1个回答
1
投票

您的方法是正确的,只需将列转换为UnboundCheckBoxField并使用HeaderChecked属性。

代码段(C#):

protected void button1_Click(object sender, EventArgs e)
{
    UnboundCheckBoxField checkboxField = (WebDataGrid1.Columns[0] as UnboundCheckBoxField);

    checkboxField.HeaderChecked = !checkboxField.HeaderChecked;
}

代码片段(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:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.