Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 8th, 2008, 10:54 PM
Authorized User
Join Date: Apr 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default multi column database source for drop down list

I have a dependent drop down list that needs to be populated by every column in a row, but NOT concatenated. Each column in the row needs to be a separate list item. There has got to be an easy way to do this without writing 15 pages of code.

Does anyone know how to do this? I'm using VWD and Visual Basic to build the webpage. I've spent a week searching for an answer and I am ready to throw the computer through the wall I'm so frustrated with this problem.


  #2 (permalink)  
Old April 9th, 2008, 07:26 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

Hmm. This seems like an odd request.

Databinding directly to your datasource is going to be out of the question since, as you probably know, you can only bind to 2 columns within a DataSource. (DataTextField and DataValueField)

What you are probably going to have to do is some logic such as this

For Each dr As DataRow in dt.Rows
    For Each dc as DataColumn in dt.Columns
        dropDownList1.Items.Add(new ListItem(Convert.ToString(dr[dc]), Convert.ToString(dr[dc])))
This code will iterate through each Row in your data source and then iterate through each column in each row of the datasource (here i have assumed that dt is of type DataTable). Is this what you are looking for?


================================================== =========
Read this if you want to know how to get a correct reply for your question:
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #3 (permalink)  
Old April 12th, 2008, 09:24 PM
Authorized User
Join Date: Apr 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

Your code got me close, but I'm struggling with the last piece of the puzzle. Let me lay out the tables and the desired operation:

Table 1 (tied to dropdownlist1)
Id Chapter
1 21
2 22
3 23

Table 2 (tied to dropdownlist2)
Id Section1 Section2 Section3
1 11 21 31
2 12 22 32
3 13 23 33

The tables are a lot larger, but this gives you an ideas of how they're set up. The way this is supposed to work is the user selects a Chapter from dropdownlist1. This part works fine. Then, based on the the selected chapter dropdownlist2 is populated with a list of each section in the matching Id row as a separate item in the dropdownlist. The user then selects a Section from dropdownlist2. Getting dropdownlist2 to populate properly is what I can't seem to get right.

I'm trying to convert a macro to a web-based application, and for this functionality I used Select case and With statements to populate the two dropdownlists. I was hoping to use a database to store all of the variables instead of writing 200 lines of code. I'm still playing with your code to get this to work, but so far no dice.

Thanks for your input!

  #4 (permalink)  
Old August 4th, 2008, 05:05 PM
Authorized User
Join Date: Feb 2008
Location: london, , United Kingdom.
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts

I might be a bit clueless here (no real surprise, given that I'm a complete novice), but I'm wondering if you couldn't just have the first table's Id be passed on to a dynamic select statement to generate table 2 as and when needed?

I do something similar with a couple of dropdown lists in classic asp, from what I've understood of your problem.
or you might even use AJAX and send the result of table1 dropdown to the server immediately after the user selects an option, then have code waiting to repopulate the same dropdown box with the sections information.

I don't know, I might be missing the complexity of it.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
multi Drop down list in PHP Star007 Pro PHP 6 March 17th, 2012 02:18 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Multi Drop Down List epkon Pro PHP 0 December 1st, 2006 11:09 AM
List Tool Multi Column? Vendlus BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 April 28th, 2006 06:39 AM
Data Grid Drop Down List Column bmains ASP.NET 1.0 and 1.1 Professional 4 September 21st, 2004 08:39 AM

All times are GMT -4. The time now is 12:10 AM.

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