0
votes

I can't figure out how to set the "checked" value of certain checkboxes in a checkboxlist during page load. So far I have this, but it doesn't work.

    For Each DataRow As DataRow In groupDataset().Tables(0).Rows
        Dim i As Integer
        For i = 0 To cblGroups.Items.Count - 1
            Response.Write(cblGroups.DataValueField)
            If DataRow("memberID").ToString = cblGroups.DataValueField Then
                cblGroups.Items(i).Selected = True
            End If
        Next
    Next

Is this even possible?

Thanks

1
Have you tried to step into this code and check if the Selected=True line is reached by some positive comparisons? - Steve

1 Answers

1
votes

Try this. You need to look at each item in the checkboxlist, not the datavaluefield of the group itself.

  For Each DataRow As DataRow In groupDataset().Tables(0).Rows
    Dim i As Integer
    For i = 0 To cblGroups.Items.Count - 1
      Response.Write(cblGroups.Items(i).Value)
      If DataRow("memberID").ToString = cblGroups.Items(i).Value Then
    cblGroups.Items(i).Selected = True
      End If
    Next
  Next