I have a form that is used to update user's profile. The user can have multiple roles that I'm trying to display using a CheckBoxList.
When initially selecting a user the code below works. If I select another user, the checkboxes in my form are not filled out (all are unselected). Additionally, if I update a user and then select another user, the checkboxes are filled correctly.
Below is the code I am using. Thanks in advance for your help. (GV= Gridview FV = Formview)
Expand|Select|Wrap|Line Numbers
- Dim UNameStr As New Label
- 'Get username
- UNameStr.Text = gvUser.SelectedRow.Cells(3).Text
- 'Get User's Roles
- Dim userroles() As String = Roles.GetRolesForUser(UNameStr.Text)
- Dim NewRoles As CheckBoxList
- 'Find CheckBoxList
- NewRoles = DirectCast(fvUserEdit.FindControl("cbRoles"), CheckBoxList)
- 'Uncheck everything in the CheckBoxList
- NewRoles.ClearSelection()
- 'Select Roles User Is In
- For Each li As ListItem In NewRoles.Items
- For indexA As Integer = 0 To userroles.Length - 1
- If li.Value.ToString = userroles(indexA).ToString Then
- 'If the values match, set the checkbox to true
- li.Selected = True
- End If
- Next
- Next