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

x
?
Solved

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

Posted on 2006-05-22
2
Medium Priority
?
3,648 Views
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.

0
Comment
Question by:leon24
2 Comments
 
LVL 3

Expert Comment

by:trainsdse
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'
0
 
LVL 28

Accepted Solution

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

Connection.Open();
reader = Command.ExecuteReader();

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

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

reader.Close()
Connection.Close()
0

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