473,387 Members | 1,548 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.

ListBox and/or SQL/ADO question

I am populating listbox with a datreader.
DateReader sqlcommand is dynamic, based on several user selections
Listbox DataValueField is set to the tables primary key
Listbox DataTextField is multiple fields concatentated from SQL statement
For example SELECT [field1] + ' ' + [field2] AS showText...
Listbox would show the following
Joe Smith...
Mary Smith ...
John Doe....

I want to include a "row number" in the DataTextField as such
Listbox would show the following
1. Joe Smith...
2. Mary Smith...
3. John Doe...

Is there a way I can use an experssion in my SQL statement to create these
values or include the Listbox ListItem value as part of the DataTextField.

Thanks in advance,
Paul
Nov 17 '05 #1
3 1298
Forgot to mention...
I need to use a ListBox because I need multiselect capabilities for the
items, therefore I don't thing DataGrid, DataList, or Repeater will work for
my needs.
Nov 17 '05 #2
I think you're going to have to use a DataTable instead of a DataReader,
since it looks like you're wanting to manipulate the data prior to using it
as a Data Source for your ListBox. The DataTable is disconnected, and holds
all the results of the query, instead of only one row at a time. You can
therefore manipulate the data, change the order of it, filter it, add
columns (for example, you might want to add a column with a unique
identifier for the "value" property of your List Items), etc.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Paul W" <pd*******@comcast.net> wrote in message
news:_tgjb.780003$Ho3.206558@sccrnsc03...
I am populating listbox with a datreader.
DateReader sqlcommand is dynamic, based on several user selections
Listbox DataValueField is set to the tables primary key
Listbox DataTextField is multiple fields concatentated from SQL statement
For example SELECT [field1] + ' ' + [field2] AS showText...
Listbox would show the following
Joe Smith...
Mary Smith ...
John Doe....

I want to include a "row number" in the DataTextField as such
Listbox would show the following
1. Joe Smith...
2. Mary Smith...
3. John Doe...

Is there a way I can use an experssion in my SQL statement to create these
values or include the Listbox ListItem value as part of the DataTextField.

Thanks in advance,
Paul

Nov 17 '05 #3
Thanks for the insight Kevin,
I was thinking of speed with the datareader, but I am not popluating the
listbox with a large number of records, so your solution should work.
Paul
Nov 17 '05 #4

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

Similar topics

4
by: f_salazar | last post by:
English Version !! Hi !! I have a page with a Form, inside the form I have listbox with 'X' elements. Wend I submit the page, an ASP process inside the page have to read those elements and...
3
by: Stimp | last post by:
I have a listbox of values that I populate from a database. I want the user to be able to re-order the list (by first selecting an item and then clicking 'up' or 'down' buttons) and then save...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
21
by: Bilal Abbasi | last post by:
I realize that you can add items to a list box as objects so you can have access to more than just one property like the itemindex in vb6. Question I have is how do I cause the listbox to show a...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
2
by: dan NY | last post by:
I'm a struggling new VB Applications user that has what may be a simple question, but I've been struggling with it. I'm using a response to a message box YesNo question to cause one of two...
3
by: caracolito1975 | last post by:
Hi to every one!!!! For some time now I'm programing in .NET and I have a question in using ListBox I need to databind a collection to a ListBox. My code is something like this: using...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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
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.