2

我有一个 WebDataGrid 和一个 UnboundCheckBoxField 列。我希望能够从后面的代码中选中和取消选中标题中的复选框,从而选择或取消选择所有项目。有 WebDataGrid1.Columns["IsActive"].Header 但我无法设置任何值。

4

1 回答 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>

动图:

在此处输入图像描述

于 2019-03-25T15:34:23.750 回答