Row / check iterations in RadGrid

I have a Telerik RadGrid with a GridTemplateColumn that contains a checkbox:

<telerik:GridTemplateColumn HeaderText="MINE" UniqueName="MyTemplateColumn">
     <ItemTemplate>
          <asp:CheckBox id="MyCheckBox" runat="server"></asp:CheckBox>
     </ItemTemplate>
</telerik:GridTemplateColumn>

I want to check the checked box based on the value read from the database. I could handle the ItemDataBound event and read the database when each row is bound, but this leads to n searches. Instead, I want to process a DataBound, and then set all the values ​​at once. So, in this method, I want the code to look like this:

// read all values from database first, then...
foreach(var chkbox in MyRadGrid.MasterTableView.Columns.FindByUniqueName("MyTemplateColumn").FindControl("MyCheckBox")) {
    chkbox.Checked = oneValue;
}

This does not work, because FindControl is not a GridColumn method, and it will not generate an iterable list of flags. What is the correct way to iterate using checkboxes in a template column? Thank!

+5
2

Telerik :

foreach (GridDataItem item in MyRadGrid.MasterTableView.Items) 
{ 
  CheckBox chk = (CheckBox)item.FindControl("MyCheckBox");
  // Set the value here
}

, -!

+16

.. .

' -

Private _GroupMembers As New Hashtable

'    GetMembers() As Boolean

    Try

        Dim da As New DataAccess
        Dim ht As New Hashtable
        Dim i As Int16 = 0

        ht.Add("CAC", Session("cac"))
        ht.Add("GroupID", _GroupID)
        If da.GetData("rap_spGetGroupMemberList", ht) = True Then
            If da.SQLDataRows.HasRows Then
                While da.SQLDataRows.Read()
                    i = i + 1
                    _GroupMembers.Add(i, da.SQLDataRows("UserID"))
                End While
            End If
            da.SQLDataRows.Dispose()
        End If

        da = Nothing

    Catch ex As Exception
        Console.Write(ex.Message)
    End Try
End Function

'    Sub RadGrid2_ItemDataBound ( ByVal , ByVal e As Telerik.Web.UI.GridItemEventArgs) RadGrid2.ItemDataBound

    Try

        If e.Item.IsDataBound Then
            If Not e.Item.DataItem("UserID") Is Nothing Then
                If Not IsDBNull(e.Item.DataItem("UserID")) Then
                    Dim UserID As Long = e.Item.DataItem("UserID")
                    If _GroupMembers.ContainsValue(UserID) Then
                        e.Item.Selected = True
                    End If
                End If
            End If
        End If

    Catch ex As Exception
        Console.Write(ex.Message)
    End Try
End Sub
+1

All Articles