You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在后端获取Infragistics WebDataGrid中UnboundCheckBoxField列的值?

问题:在Infragistics WebDataGrid回发时获取未绑定复选框列的选中状态

我使用的WebDataGrid片段如下:

<ig:WebDataGrid ID="WebDataGrid1" runat="server" >
    <Columns>
        <ig:UnboundCheckBoxField Key="SelectedId" >
        </ig:UnboundCheckBoxField>
    </Columns>
</ig:WebDataGrid>

需求是在回发时遍历SelectedId列,检查哪些复选框被选中。有人推荐了以下代码:

For Each row As WebDataGridRow In WebDataGrid1.Rows
        Dim checkBox As WebDataGridCell = TryCast(row.Items.FindItemByKey("SelectedId"), WebDataGridCell)

        If checkBox IsNot Nothing AndAlso checkBox.Controls.Count > 0 Then
            Dim checkBoxControl As CheckBox = TryCast(checkBox.Controls(0), CheckBox)

            If checkBoxControl IsNot Nothing Then
                Dim isChecked As Boolean = checkBoxControl.Checked
            End If
        End If
    Next

但在我的Infragistics版本(Infragistics45.Web.v21.2, Version=21.2.20212.9)中,编译器提示WebDataGridRow和WebDataGridCell类型未定义。尝试去掉类型声明后:

For Each row In WebDataGrid1.Rows
    Dim checkBox = row.Items.FindItemByKey("SelectedID")
    ...
Next

此时row的类型为Infragistics.Web.UI.GridControls.GridRecord,checkBox的类型为Infragistics.Web.UI.GridControls.GridRecordItem,但找不到指向复选框的Controls属性,请问该如何获取复选框的值?


解决方案

在Infragistics 21.2版本的WebDataGrid中,无需通过查找控件的方式获取未绑定复选框的选中状态,UnboundCheckBoxField的值会自动同步到GridRecordItem的Value属性中,直接读取即可:

For Each row As Infragistics.Web.UI.GridControls.GridRecord In WebDataGrid1.Rows
    Dim checkBoxItem As Infragistics.Web.UI.GridControls.GridRecordItem = row.Items.FindItemByKey("SelectedId")
    If checkBoxItem IsNot Nothing Then
        ' 将Value转换为Boolean类型,获取选中状态
        Dim isChecked As Boolean = Convert.ToBoolean(checkBoxItem.Value)
        ' 此处添加选中状态的处理逻辑
    End If
Next

说明

旧版本的WebDataGrid可能使用WebDataGridRow/WebDataGridCell的模型,但21.2版本已更新为GridRecord/GridRecordItem架构。对于未绑定复选框列,控件内部会自动维护选中状态并同步到GridRecordItem.Value,无需手动查找DOM控件,这种方式更可靠且代码更简洁。


内容的提问来源于stack exchange,提问作者Sammybar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 22:50:57