Results 1 to 4 of 4

Thread: dropdownlist problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    92

    Question dropdownlist problem

    Hi !

    I have a real problam with dropdownlist.

    I need to add a data selected from Database into the dropdownlist.

    can someone please send me an example of how i can do such.

    to make things short, how can I add data from recordset to a dropdwon list .

    thanks.

  2. #2
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    set the dropdownlist.datasource to ur dataSet

    set the dropdownlist.datamember to the table name in ur recordset

    set the dropdownlist.datatextfield to the field which will be the text to display for an option in the list

    set the dropdownlist.datavaluefield to the field which will hold the VALUE for each option in ur list

    then execute dropdownlist.databind()

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    92

    ...

    do you have some code example for the step you gave.

    10x.

  4. #4
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    Code:
    <script language="WHAT DO I PUT HERE FOR VISUAL BASIC!?">
    sub BindComps()
        dim cnOzSite as oleDbConnection
        dim adOzSite as oledbDataAdapter
        dim dsComps as new DataSet
        dim dsDivs as new Dataset
        dim connStr, sql as string
        dim TMPAREA as Integer
    
        TMPAREA = 1
    
        connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\OzSite.mdb"
        sql="SELECT Name, CompID FROM Competition WHERE AreaID = " & TMPAREA & ";"
    
        cnOzSite = new oledbConnection(connStr)
        cnOzSite.open
    
        adOzSite = new oledbDataAdapter(sql, cnOzSite)
        adOzSite.fill(dsComps, "dtComps")
    
        ddlComps.datasource = dscomps
        ddlComps.datamember="dtComps"
        ddlcomps.datatextfield = "Name"
        ddlcomps.datavaluefield = "CompID"
        ddlcomps.databind()
        ddlComps.selectedindex = 0
        bindDivs()
    
    end sub
    </script>
    Thats what i had.

    It connects to an Access Database
    Last edited by SkiNLaB; Aug 6th, 2002 at 05:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width