Databinding to DropDownList


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Databinding to DropDownList

  1. #1
    Jon Lepeska Guest

    Databinding to DropDownList

    How can I populate a dropdownlist server control with data from database??
    I'm using a data reader and setting the datasource property of my
    asp:dropdownlist control to that data reader. I know I'm getting data
    returned....it's just not appearing in the dropdown. I'm not getting any
    errors either. If anyone has an example of this....please send it to me...

    thanks.






  2. #2
    c2i - Richard Clark Guest

    Re: Databinding to DropDownList

    Here is an article about it (sorry but text in french ;-)
    http://www.c2i.fr/asp/code.asp?IDCode=145


    --
    Richard Clark - rc@c2i.fr
    ______________________________________________
    NOUVEAU : Liste de diffusion sur MS.NET
    Inscription en envoyant un mail :
    ----------------------------------------------
    dotnetfrance-subscribe@yahoogroups.com
    ----------------------------------------------
    http://www.c2i.fr - Le portail francophone
    Visual Basic,VB.NET,ASP, ASP.NET
    + de 517 aides disponibles (15/02)
    ______________________________________________
    "Jon Lepeska" <jonl@equarius.com> wrote in message
    news:3ac138b2$1@news.devx.com...
    > How can I populate a dropdownlist server control with data from database??
    > I'm using a data reader and setting the datasource property of my
    > asp:dropdownlist control to that data reader. I know I'm getting data
    > returned....it's just not appearing in the dropdown. I'm not getting any
    > errors either. If anyone has an example of this....please send it to

    me...
    >
    > thanks.
    >
    >
    >
    >
    >




  3. #3
    dave Guest

    Re: Databinding to DropDownList


    Hi Jon,
    here you go..

    the code

    Dim sqlText as String = "select * from authors"
    Dim ds as Dataset = New Dataset()
    Dim sqlConn as SQLConnection = New SQLConnection( myConnectionString )
    Dim sqlCmd as SQLDataSetCommand = New SQLDataSetCommand( sqlText,sqlConn
    )

    sqlCmd.FillDataset( ds,"Authors" )
    authorlname.datasource = ds.Tables("Authors").DefaultView
    authorlname.DataValueField = "au_id"
    authorlname.DataTextField = "au_lname"
    authorlname.DataBind()



    The control --
    <select id="authorlname" runat="server" >


    Cheers!
    dave
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    http://www.123aspx.com
    The Largest ASP.NET Directory!
    Find the latest ASP.NET resources --
    Subscribe to our newsletter!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    "Jon Lepeska" <jonl@equarius.com> wrote:
    >How can I populate a dropdownlist server control with data from database??
    >I'm using a data reader and setting the datasource property of my
    >asp:dropdownlist control to that data reader. I know I'm getting data
    >returned....it's just not appearing in the dropdown. I'm not getting any
    >errors either. If anyone has an example of this....please send it to me...
    >
    >thanks.
    >
    >
    >
    >
    >



  4. #4
    dave Guest

    Re: Databinding to DropDownList


    Hi Jon,
    here you go..

    the code

    Dim sqlText as String = "select * from authors"
    Dim ds as Dataset = New Dataset()
    Dim sqlConn as SQLConnection = New SQLConnection( myConnectionString )
    Dim sqlCmd as SQLDataSetCommand = New SQLDataSetCommand( sqlText,sqlConn
    )

    sqlCmd.FillDataset( ds,"Authors" )
    authorlname.datasource = ds.Tables("Authors").DefaultView
    authorlname.DataValueField = "au_id"
    authorlname.DataTextField = "au_lname"
    authorlname.DataBind()



    The control --
    <select id="authorlname" runat="server" />


    Cheers!
    dave
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    http://www.123aspx.com
    The Largest ASP.NET Directory!
    Find the latest ASP.NET resources --
    Subscribe to our newsletter!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    "Jon Lepeska" <jonl@equarius.com> wrote:
    >How can I populate a dropdownlist server control with data from database??
    >I'm using a data reader and setting the datasource property of my
    >asp:dropdownlist control to that data reader. I know I'm getting data
    >returned....it's just not appearing in the dropdown. I'm not getting any
    >errors either. If anyone has an example of this....please send it to me...
    >
    >thanks.
    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center