Search code examples
vb.netwebformsinfragisticswebdatagrid

How to navigate the Infragistics' WebDataGrid control in the back end looking for the values of an UnboundCheckBoxField column?


This is a fragment of my WebDataGrid:

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

In the postback I want to iterate all the SelectedId column checking what was checked. I was suggested the following code:

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

The problem is the compiler says the types WebDataGridRow and WebDataGridCell are not defined, at least with my version of Infragistics (Infragistics45.Web.v21.2, Version=21.2.20212.9) Am I missing something?

Removing the types I tried:

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

The row variant happen to be of the Infragistics.Web.UI.GridControls.GridRecord type. And the checkBox variant is a Infragistics.Web.UI.GridControls.GridRecordItem type. But no property looks to point to the checkbox. (The checkBox doesn't has the Controls property)

How to access the value of the checkbox at this point?


Solution

  • Definitely the suggested code is wrong: the types WebDataGridRow and WebDataGridCell never existed. The code that works is the following:

    Dim result As String = ""
    For Each row In WebDataGrid1.Rows
        Dim cell As GridRecordItem = row.Items.FindItemByKey("ChkSelectedID")
    
        If cell IsNot Nothing Then
            Dim value = cell.Value
            Dim isChecked As Boolean = value
            result &= IIf(isChecked, "1", "0")
        Else
            result &= "-"
        End If
    Next
    

    And another important point: run this code in the WebDataGrid.PreRender event. Before that it will return all the checkboxes as unchecked.