Populating DropDownList

H

Hugh McLaughlin

Hello Everyone and thanks for your help in advance. I am
developing a class library that reads a SQL Server table
of names and ID's. I want to populate a dropdownlist with
the data, however, names in the table may appear more
than once. I only want to display the name in the
dropdownlist once. My initial thought wat to create an
arraylist, then loop through each record, adding a new
name upon each new name encountered. But I want the name
to display in the dropdownlist, but the associated value
to be the IDNumber for the particular name. This would be
pretty straightforward if I was doing this in a code-
behind, simply adding to the list as each record was
read. But since this is a separate class, I have to
return something that can be bound to the dropdownlist
control. I am not eactly sure how to go about
accomplishing this. Any help would be greatly
appreciated. Thanks.
 
P

Peter van der Goes

Hugh McLaughlin said:
Hello Everyone and thanks for your help in advance. I am
developing a class library that reads a SQL Server table
of names and ID's. I want to populate a dropdownlist with
the data, however, names in the table may appear more
than once. I only want to display the name in the
dropdownlist once. My initial thought wat to create an
arraylist, then loop through each record, adding a new
name upon each new name encountered. But I want the name
to display in the dropdownlist, but the associated value
to be the IDNumber for the particular name. This would be
pretty straightforward if I was doing this in a code-
behind, simply adding to the list as each record was
read. But since this is a separate class, I have to
return something that can be bound to the dropdownlist
control. I am not eactly sure how to go about
accomplishing this. Any help would be greatly
appreciated. Thanks.

Have you considered creating a query from the table that disallows
duplicates (allowing SQL to do the dirty work for you), then using the
results to populate your drop-down list?
 

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

Top