How do I bind data to a ComboBox?

ASP.NET: Easiest way to bind data to drop down list?

  • I've been using someone else's code, which does this all by hand. Works great, but isn't there an easier way to bind data to a DDL control? I'd like to start with a new C# web app, and add a DDL, then bind data using the properties of the drop list. Looks like everything is OK, but the list is always empty when I test it. I add sqlDataAdapter, sqlConnection1, and finally a dataset. Am I just missing the final trigger or something?

  • Answer:

    First off, did you confirmat that your DataSet has the data in it? Assuming your Drop down list is called "lstPeople" and your DataSet is called "dsPeople": //Set the displayed text for the list this.lstPeople.DataTextField = "FirstName"; //Set the value field for the list this.lstPeople.DataValueField = "PersonID"; //Set the DataSource this.lstPeople.DataSource = dsPeople; //Finally, do your DataBind this.lstPeople.DataBind();

sideshot... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.