473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB.NET Selecting Items In CheckBoxList

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)

Expand|Select|Wrap|Line Numbers
  1. Dim UNameStr As New Label
  2.  
  3.         'Get username
  4.         UNameStr.Text = gvUser.SelectedRow.Cells(3).Text
  5.  
  6.         'Get User's Roles
  7.         Dim userroles() As String = Roles.GetRolesForUser(UNameStr.Text)
  8.         Dim NewRoles As CheckBoxList
  9.  
  10.         'Find CheckBoxList
  11.         NewRoles = DirectCast(fvUserEdit.FindControl("cbRoles"), CheckBoxList)
  12.  
  13.         'Uncheck everything in the CheckBoxList
  14.         NewRoles.ClearSelection()
  15.  
  16.         'Select Roles User Is In
  17.         For Each li As ListItem In NewRoles.Items
  18.             For indexA As Integer = 0 To userroles.Length - 1
  19.                 If li.Value.ToString = userroles(indexA).ToString Then
  20.                     'If the values match, set the checkbox to true
  21.                     li.Selected = True
  22.                 End If
  23.             Next
  24.         Next
Mar 10 '14 #1
1 3905
pod
298 100+
try rebinding the datasource if you are using one
Mar 11 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amin Gunawan via .NET 247 | last post by:
I would like to put a combo box in a column of a datagrid. I've seen the samples in the MSDN library of other sources, butall samples didn't catch the 'DOWN/UP' keystroke. It means thatwhen I select...
5
by: Mark | last post by:
Hi - is it possible to pass a comma delimeted list to a javascript function, which will then loop through the list, and check against a listboxs items, and if the value in the list, corresponds to...
7
by: CJ Taylor | last post by:
I have the following code. Dim lItem As ListViewItem For Each lItem In Me.lv_Search.Items lItem.Selected = True Next
4
by: Brian | last post by:
How can I use javascript to select Items in a List/Menu? For example: (value1, value2) will select value1 and value2 in a list menu....
2
by: miller504 | last post by:
I'm trying to select several items from a listbox. My code is working except when the form loads the first time. I have the code to select the items inside sub Initialize_CbLeague. If I call sub...
1
by: michael.martinek | last post by:
Greetings! I've recently been trying to do something, which apparently looks like it may be a little odd.. I'm not finding anything in the manuals or anywhere on the web where something similiar...
0
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi (asp.net 2.0, vb.net, SQL Server 2005 Express) I have a Form where users can select multiple preferences via a CheckListBox. Those items are stored in a SQL 2005 database and are related to...
2
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.