Array not working properly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eknee1417
    New Member
    • Mar 2008
    • 1

    Array not working properly

    [code=vb]' Determine what roles the selected user belongs to
    Dim strSelectedUser Name As String = ddlUserList.Sel ectedValue
    Dim strSelectedUser sRoles() As String = Roles.GetRolesF orUser(strSelec tedUserName)
    Dim strRoleNames() As String = Roles.GetAllRol es.Clone

    ' Loop through the Repeater's Items and check or uncheck the checkbox as needed
    For Each ri As RepeaterItem In rptrUsersRoleLi st.Items

    ' Programmaticall y reference the CheckBox
    Dim RoleCheckBox As CheckBox = CType(ri.FindCo ntrol("RoleChec kBox"), CheckBox)


    ' See if RoleCheckBox.Te xt is in selectedUsersRo les
    If Array.IndexOf(s trSelectedUsers Roles, RoleCheckBox.Te xt) Then
    RoleCheckBox.Ch ecked = True
    Else
    RoleCheckBox.Ch ecked = False
    End If
    Next[/code]
    The code above is supposed to populate check boxes from a repeater in .Net that contains User Roles. For some reason though on the first entry the first time through the code it does not check the box "administrator" , which it should.
    Last edited by debasisdas; Mar 28 '08, 09:50 AM. Reason: added code=vb tags
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hello
    U just change the line 2 to
    Code:
     Dim strSelectedUserName As integer = ddlUserList.SelectedValue
    Then try

    Faisal

    Originally posted by eknee1417
    [code=vb]' Determine what roles the selected user belongs to
    Dim strSelectedUser Name As String = ddlUserList.Sel ectedValue
    Dim strSelectedUser sRoles() As String = Roles.GetRolesF orUser(strSelec tedUserName)
    Dim strRoleNames() As String = Roles.GetAllRol es.Clone

    ' Loop through the Repeater's Items and check or uncheck the checkbox as needed
    For Each ri As RepeaterItem In rptrUsersRoleLi st.Items

    ' Programmaticall y reference the CheckBox
    Dim RoleCheckBox As CheckBox = CType(ri.FindCo ntrol("RoleChec kBox"), CheckBox)


    ' See if RoleCheckBox.Te xt is in selectedUsersRo les
    If Array.IndexOf(s trSelectedUsers Roles, RoleCheckBox.Te xt) Then
    RoleCheckBox.Ch ecked = True
    Else
    RoleCheckBox.Ch ecked = False
    End If
    Next[/code]
    The code above is supposed to populate check boxes from a repeater in .Net that contains User Roles. For some reason though on the first entry the first time through the code it does not check the box "administrator" , which it should.

    Comment

    Working...