473,491 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Listbox Selected Value

I'm using ASP.Net and SQL Server.
I have a listbox looks up data from a table and fills the listbox.
I have a stored procedure that looks up the selected values and tries to
show them as selected in the listbox. My FOR NEXT LOOP gets stuck on one
record in the datatable. There are 4 records in the datatable and only the
first one is selected. It never moves past the first record.

MyCommand.Fill(dsCom, "tblCommRealtorAssociation")

dtCom = dsCom.Tables("tblCommRealtorAssociation")

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(0)( "CommunityID")

Next
Nov 18 '05 #1
3 5725
I think you should be referencing the variable 'i' in the Rows indexer as
follows:

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(i)( "CommunityID")

Next

"Big E" <no****@nospam.com> wrote in message
news:eS****************@tk2msftngp13.phx.gbl...
I'm using ASP.Net and SQL Server.
I have a listbox looks up data from a table and fills the listbox.
I have a stored procedure that looks up the selected values and tries to
show them as selected in the listbox. My FOR NEXT LOOP gets stuck on one
record in the datatable. There are 4 records in the datatable and only the
first one is selected. It never moves past the first record.

MyCommand.Fill(dsCom, "tblCommRealtorAssociation")

dtCom = dsCom.Tables("tblCommRealtorAssociation")

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(0)( "CommunityID")

Next

Nov 18 '05 #2
You are right. Thanks.
How can I set more than one selected value on a listbox. It only sets the
last one in the dataset.

Thanks.

Big E

"Adam Barker" <ms***************@q-state.co.uk> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl...
I think you should be referencing the variable 'i' in the Rows indexer as
follows:

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(i)( "CommunityID")

Next

"Big E" <no****@nospam.com> wrote in message
news:eS****************@tk2msftngp13.phx.gbl...
I'm using ASP.Net and SQL Server.
I have a listbox looks up data from a table and fills the listbox.
I have a stored procedure that looks up the selected values and tries to
show them as selected in the listbox. My FOR NEXT LOOP gets stuck on one
record in the datatable. There are 4 records in the datatable and only the first one is selected. It never moves past the first record.

MyCommand.Fill(dsCom, "tblCommRealtorAssociation")

dtCom = dsCom.Tables("tblCommRealtorAssociation")

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(0)( "CommunityID")

Next


Nov 18 '05 #3
Set

ListBox1.SelectionMode = ListSelectionMode.Multiple

and

ListBox1.Items[0].Selected = true

which means you may have to slightly rework your database access code.

"Big E" <no****@nospam.com> wrote in message
news:e5**************@TK2MSFTNGP10.phx.gbl...
You are right. Thanks.
How can I set more than one selected value on a listbox. It only sets the
last one in the dataset.

Thanks.

Big E

"Adam Barker" <ms***************@q-state.co.uk> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl...
I think you should be referencing the variable 'i' in the Rows indexer as
follows:

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(i)( "CommunityID")

Next

"Big E" <no****@nospam.com> wrote in message
news:eS****************@tk2msftngp13.phx.gbl...
I'm using ASP.Net and SQL Server.
I have a listbox looks up data from a table and fills the listbox.
I have a stored procedure that looks up the selected values and tries to show them as selected in the listbox. My FOR NEXT LOOP gets stuck on one record in the datatable. There are 4 records in the datatable and only

the first one is selected. It never moves past the first record.

MyCommand.Fill(dsCom, "tblCommRealtorAssociation")

dtCom = dsCom.Tables("tblCommRealtorAssociation")

Dim i As Integer

For i = 0 To dtCom.Rows.Count - 1

lstCommunities.SelectedValue =
dsCom.Tables("tblCommRealtorAssociation").Rows(0)( "CommunityID")

Next



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2900
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
1
8341
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
6
2856
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
4
2423
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
6
5176
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
10
3264
by: Adam Clauss | last post by:
I have a page containing a list box. This list may contain duplicate items - in which the ORDER is important. ex: a b b a is significant as compared to: b
4
1845
by: collie | last post by:
HI, I need to populate 2 listboxes from a db. When the page loads then the first listbox needs to be populated and based on selection from that listbox the second listbox needs to be populated...
2
3814
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
28
2257
by: cjobes | last post by:
Hi all, I need to populate a listbox from a table column. The column has multiple entries of usernames and I need to pull a unique set of usernames. The table is part of an untyped Dataset that...
2
6293
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single...
0
7115
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
6978
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...
0
7154
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
7190
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...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4578
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...
0
3086
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...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
280
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...

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.