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

Discussion in 'ASP .Net' started by Joey Liang via DotNetMonster.com, May 13, 2005.

  1. 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

    --
    Message posted via http://www.dotnetmonster.com
     
    Joey Liang via DotNetMonster.com, May 13, 2005
    #1
    1. Advertising

  2. 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.


    "Joey Liang via DotNetMonster.com" <> skrev i
    melding news:...
    > 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
    >
    > --
    > Message posted via http://www.dotnetmonster.com
     
    Eirik Eldorsen, May 13, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    825
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,078
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    552
    msimmons
    Jul 16, 2009
  4. bjkaledas

    Need to Bind Database value to Drop Down List in GridView

    bjkaledas, May 14, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    585
    KyleK
    May 17, 2007
  5. Replies:
    5
    Views:
    320
Loading...

Share This Page