473,787 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop datatable and select checkboxlist item based on the datatable field values

50 New Member
I am trying to display value of the field ("UserID") for every row exists in datatable to checkboxlist(ma ke the checkboxlist item selected).
I used for loop, but only the field value from last row of RoleUsers table is selected in the checkboxlist.

Here is my code

Expand|Select|Wrap|Line Numbers
  1.    Private Sub DisplayRoleUser()
  2.     Dim conn As SqlConnection
  3.     Dim cmd As SqlCommand 
  4.         Dim drDataReader As SqlDataReader
  5.         Dim dtDataTable As New DataTable
  6.  
  7.  
  8.         conn = New SqlConnection("Data Source=(local);Initial Catalog=BHPTrackingSystem;User ID=sa;Password=Safetec2011")
  9.         conn.Open()
  10.         cmd = New SqlCommand("SELECT UserID ,RoleID FROM RoleUsers WHERE RoleID=@RID ", conn)
  11.         cmd.Parameters.Add("@RID", SqlDbType.Int)
  12.         cmd.Parameters("@RID").Value = lstRole.SelectedValue
  13.  
  14.         drDataReader = cmd.ExecuteReader()
  15.         dtDataTable.Load(drDataReader)
  16.         Dim i As Integer
  17.         If dtDataTable.Rows.Count > 0 Then
  18.             For i = 0 To dtDataTable.Rows.Count - 1
  19.                 chkUser.SelectedValue = dtDataTable.Rows(i).Item("UserID")
  20.             Next
  21.         End If
  22.  
  23.         cmd.Dispose()
  24.         conn.Close()
  25.  
Can you guys please tell me where do i get wrong? Your help is much appreciated. THank you very much !
Aug 18 '11 #1
3 7555
snehasismishra1
18 New Member
Hi Beemomo,

Please find the below code. I guess it will help you.

DataTable table = new DataTable();
table.Columns.A dd("Dosage", typeof(int));
table.Columns.A dd("Drug", typeof(string)) ;
table.Columns.A dd("Patient", typeof(string)) ;
table.Columns.A dd("Date", typeof(DateTime ));

table.Rows.Add( 25, "Indocin", "David", DateTime.Now);
table.Rows.Add( 50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add( 10, "Hydralazin e", "Christoff" , DateTime.Now);
table.Rows.Add( 21, "Combivent" , "Janet", DateTime.Now);
table.Rows.Add( 100, "Dilantin", "Melanie", DateTime.Now);

CheckBoxList1.R epeatColumns = 1;
CheckBoxList1.D ataSource = table;
CheckBoxList1.D ataTextField = "Drug";

CheckBoxList1.D ataBind();

If you have any concern please let me know.

Thanks,
Snehasis
Aug 19 '11 #2
beemomo
50 New Member
Thank you for your reply, Snehasis.
I have been away from workstation during last weekend. Sorry for my late reply.

I got my solution for the above post by replacing the for loop using the code below:

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To dtDataTable.Rows.Count - 1
  2.   chkUser.Items.FindByValue(dtDataTable.Rows(i).Item  ("UserID")).Selected = True
  3. Next 
  4.  
I appreciate your help alot! Thanks a again!

Regards,
Beemomo
Aug 22 '11 #3
snehasismishra1
18 New Member
You are Most Welcome...:)
Aug 24 '11 #4

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

Similar topics

1
7883
by: Eddie | last post by:
I have a DataTable.Select() statement with a DateTime field that is being compared to a Date: Dim drCal as DataRow() = tblCal.Select("CalendarItemDate ='12/1/2003'", "CalendarItemDate", DataViewRowState.CurrentRows) This never returns any rows because all the CalendarItemDate fields that contain the date 12/1/2003 also contain a time component! I searched until I was SICK and could not find how to truncate the time from the DateTime...
3
3488
by: RockNRoll | last post by:
Greetings, Can I select an item in a listbox based on user textbox entry and a submit button? Can you provide any code examples for what needs to occur when the user clicks submit? Thank you, -Dave
2
40062
by: Marcel Hug | last post by:
Hi NG! With a Inner-Join SQL I get my datas in a DataSet. In the table are the column Entry and Version. Like this: Entry Version 1 1 1 2 1 3
3
2013
by: sdisalvo | last post by:
I'm looking for a way to filter records in a query (or report) based on a value in a field of an adjacent record. Can this be done easily? I cannot find any info in the help files. Thanks
7
2388
convexcube
by: convexcube | last post by:
To keep a record of training levels for different tasks, I have 18 option groups with 4 options values each: 0 labelled as "None", 1 labelled as "Trainee", 2 labelled as "Competent" and 3 labelled as "Expert". I would like to develop a detailed report that will show one employees training levels based on the values of training for each of the 18 categories. For example, an employee with these values in a table: Service = 3 Cleaning = 2...
3
1979
by: Freud52 | last post by:
I've developed a test that results in standard scores from 35 to 99. Now, i need to be able, when a score for a specific scale is, let's say, >=75 and <=84, to have a predefined block of text be placed in a report. And, if the score for that same scale is >=85 and <=94, to have another text box be placed there instead, in the same place in the report. I am no programming guru, but if i'm given a simple example, i think i'd be able to tweak it to...
6
3511
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
2
5010
by: daveL | last post by:
how to uppercase a table columen in datatable select //dt is a Datatable i Need to uppercase control.text and table column data i dont know how to set loginname to upper case if (dt.Select("loginname='"+this.txLoginName.Text.ToUpper()+"'").Length>) { // Do Somthing } DaveL
4
5815
by: DaveL | last post by:
how to uppercase a table columen in datatable select //dt is a Datatable i Need to uppercase control.text and table column data i dont know how to set loginname to upper case if (dt.Select("loginname='"+this.txLoginName.Text.ToUpper()+"'").Length>) { // Do Somthing } DaveL
3
4226
by: abhijeetraje | last post by:
I am applying XSLT to WSDL to generate html pages. now, as WSDL is not having comprehensive details, i am adding XML documentation (.NET) as well in XSLT. like this.. <xsl:variable name="ddoc" select="document('CustomerCare.ManageMeterReads.ServiceContracts.xml')" /> Here is the XML documentation.... <?xml version="1.0"?> <doc> <assembly> <name>CustomerCare.ManageMeterReads.ServiceContracts</name>
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.