Results 1 to 4 of 4

Thread: DropDownList binding to SQL query

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10

    Unhappy DropDownList binding to SQL query

    Hi there,

    I have a dropdownlist at the top pf my page I wish to be populated so that all the values are a particular column from my SQL query and all the text valeus ie what the user sees are from another column.

    I have set up the connetion and a datatable ok, i think but am having problems. my code:

    VB Code:
    1. Dim myTable As New DataTable("myContactsTable")
    2.                       Dim myOtherTable As New DataTable("myDDLTable")
    3.                       objDataSet.Tables.Add(myTable)
    4.                       objDataSet.Tables.Add(myOtherTable)
    5.  
    6.                       myContacts.DataSource = objDataSet.Tables("myContacts")
    7.                       myContacts.DataBind()
    8.  
    9.                       myDDL.DataSource = myOtherTable
    10.                       myDDL.DataBind()
    11.  
    12. ... then later on :
    13.  
    14. <asp:DropDownList id="myDDL" runat="server"
    15.         DataValueField='Container.DataItem("countryCode")'
    16.             DataTextField='Container.DataItem("country")'
    17.         AutoPostBack="True">
    18.  
    19. </asp:DropDownList>

    All I get is a blank dropdown list on the page can anyone help me?

    thanks,

    beNcooKe

  2. #2
    Lively Member
    Join Date
    Jul 2001
    Posts
    81
    Code:
    <asp:DropDownList id="myDDL" runat="server"
            DataValueField="countryCode"
                DataTextField="country"
            AutoPostBack="True">
    
    </asp:DropDownList>
    Try that
    Rate my posts for a chance to win cash and prizes

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    Thanks,

    I just tried that but i get the same problem,

    any other help?

    beN

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    These need to be included before you call the DataBind method:
    VB Code:
    1. myContacts.DataTextField = "TheFieldYouWantDisplayedForTheOption"
    2. myContacts.DataValueField = "TheFieldUsedAsTheValueForTheOption"

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