473,396 Members | 2,009 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,396 software developers and data experts.

Populating DropDownList

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.
Nov 22 '05 #1
2 1568

"Hugh McLaughlin" <an*******@discussions.microsoft.com> wrote in message
news:3d****************************@phx.gbl...
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?

--
Peter - [MVP - .NET Academic]
Nov 22 '05 #2

"Hugh McLaughlin" <an*******@discussions.microsoft.com> wrote in message
news:3d****************************@phx.gbl...
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?

--
Peter - [MVP - .NET Academic]
Nov 22 '05 #3

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

Similar topics

1
by: Hugh McLaughlin | last post by:
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...
1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
3
by: to_rgoyal | last post by:
Hi All, I am creating one web base application using ASP.net and C#. I am populating dropdown lists of my web pages using database. I am using this code: con = new...
1
by: Wim | last post by:
Hi Everyone, I'm trying to speed up a Asp.net 1.1 applications' performance. The application needs to run in an environment with little bandwith and therefore pagesizes and roundtrip times shoud...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
1
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt"...
6
by: p.mc | last post by:
Hi all, I have a MS SQLServer database which has two tables, 'images' and 'photographers'. The photographer table contains a field for PhotographerID and a one for PhotographerName. The image...
0
by: Mike P | last post by:
I know how to populate a dropdown list in a gridview in edit mode when the dropdown is populated by a datasource (see below eg 1), but how do you populate the dropdown when the dropdown is...
2
by: Phil Sandler | last post by:
I am trying to do something which seems (to me) to be very simple, and yet I can't seem to figure it out. I have a gridview and a formview. When a user clicks "select" in the gridview, the...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
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:
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...

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.