Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to create a dynamic drop down list in asp.net

Posted on 2006-05-22
Medium Priority
Last Modified: 2012-05-05
Hey guys,

I need help to create a drop down list in asp.net. I need to create a drop down list, based on the items in the database (columns), and I've tried searching the internet but those sites arent really useful. Can anyone help on this? Might sound a bit stupid but I guess I've no other alternatives.

Question by:leon24

Expert Comment

ID: 16739002
Which database?  If it's sql server just bind the dropdownlist to a dataTable using the query

select column_name from information_schema.columns where table_name='sometable'
LVL 28

Accepted Solution

strickdd earned 375 total points
ID: 16743746
OdbcConnection Connection = new OdbcConnection(ConnectionString);
OdbcCommand Command = new OdbcCommand(SQLString, Connection);
OdbcDataReader reader;

reader = Command.ExecuteReader();

listBox.Datasoure = reader;
listBox.DataValueField = reader["ValueColumn"];
listBox.DataTextField = reader["TextToDisplayColumn"];

//if you want to add extra options:  listBox.Items.Insert(Index, Text);


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question