how to create a dynamic drop down list in

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

I need help to create a drop down list in 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
    LVL 3

    Expert Comment

    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

    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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    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…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now