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

  • Thread starter Joey Liang via DotNetMonster.com
  • 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
 
E

Eirik Eldorsen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top