473,411 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,411 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 1569

"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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.