Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2003, 12:31 AM
Authorized User
 
Join Date: Jul 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

 
Old November 14th, 2003, 03:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Your problem is not entiredly clear....

It's sounds like you are asking two separate question here:
1. How do I return a set of data from a class library?
2. How do I restrict the list based on the repeating names?

Question 1:
Retrieve your data using a DataAdapter and a DataSet. This is so you can get a "disconnected" dataset. Once you have that you can return the table you need. (If you have tried using a DataReader, you'll find that you can't return it and close the database connection. The DataReader will be empty. This is due to the way the DataReader interacts with the connection object. That's why you need a DataSet.)

Question 2:
From the way you explain it, I gather that you have a table with Names and IDs. Are all the IDs unique? Is there one name per ID? Why would you want to eliminate repeating names if they have different IDs? For a given set of matching names, what logic would you use to decide which ID to use if you were to eliminate the duplicates?

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating Dropdownlist in Datagrid Dynamically anup_daware .NET Framework 1.x 1 March 27th, 2006 03:38 PM
Populating DropDownList from multiple sources hawkfb63 ASP.NET 2.0 Professional 2 February 14th, 2006 06:42 PM
Populating a DataGridViewImageColumn. veggiemanuk C# 2005 0 October 8th, 2005 02:56 AM
populating a dropdownlist within a datagrid greenguitar General .NET 1 November 22nd, 2004 01:02 AM
Populating field Popper Javascript How-To 10 September 23rd, 2004 06:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.