How to bind data from database access to drop down list control?

  • Thread starter Thread starter Joey Liang via DotNetMonster.com
  • Start date Start date
J

Joey Liang via DotNetMonster.com

Hi all,
I am new to ASP.NET, i have met some problems in binding data from a
table of database to a dropdown list control. Anyone knows how to do it?if
possible can rougly write the codes or any tutorials regarding this...Thanx
in advance...

From,
Joey
 
Here's some code:

private void BindDropdownList()
{
ddlSector.DataSource = Sectors.GetAll();
ddlSector.DataTextField = "Name";
ddlSector.DataValueField = "ID";
ddlSector.DataBind();
}

Call the method BindDropdownList() in PageLoad.
Sectors.GetAll() returns a table. The table have two coloums: Name and ID.
 
Back
Top