ListBox and/or SQL/ADO question

P

Paul W

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
 
P

Paul W

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.
 
K

Kevin Spencer

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.
 
P

Paul W

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,080
Latest member
mikkipirss

Latest Threads

Top