PDA

Click to See Complete Forum and Search --> : DropDownList binding to SQL query


bencooke
Nov 9th, 2004, 05:37 AM
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:



Dim myTable As New DataTable("myContactsTable")
Dim myOtherTable As New DataTable("myDDLTable")
objDataSet.Tables.Add(myTable)
objDataSet.Tables.Add(myOtherTable)

myContacts.DataSource = objDataSet.Tables("myContacts")
myContacts.DataBind()

myDDL.DataSource = myOtherTable
myDDL.DataBind()

... then later on :

<asp:DropDownList id="myDDL" runat="server"
DataValueField='Container.DataItem("countryCode")'
DataTextField='Container.DataItem("country")'
AutoPostBack="True">

</asp:DropDownList>


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

thanks,

beNcooKe

Trunks
Nov 9th, 2004, 05:56 AM
<asp:DropDownList id="myDDL" runat="server"
DataValueField="countryCode"
DataTextField="country"
AutoPostBack="True">

</asp:DropDownList>


Try that

bencooke
Nov 9th, 2004, 06:01 AM
Thanks,

I just tried that but i get the same problem,

any other help?

beN

pvb
Nov 10th, 2004, 11:45 PM
These need to be included before you call the DataBind method:
myContacts.DataTextField = "TheFieldYouWantDisplayedForTheOption"
myContacts.DataValueField = "TheFieldUsedAsTheValueForTheOption"