Hello:
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)
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)
Code:
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
Comment