|
-
Nov 9th, 2004, 06:37 AM
#1
Thread Starter
New Member
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:
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
-
Nov 9th, 2004, 06:56 AM
#2
Lively Member
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 
-
Nov 9th, 2004, 07:01 AM
#3
Thread Starter
New Member
Thanks,
I just tried that but i get the same problem,
any other help?
beN
-
Nov 11th, 2004, 12:45 AM
#4
Hyperactive Member
These need to be included before you call the DataBind method:
VB Code:
myContacts.DataTextField = "TheFieldYouWantDisplayedForTheOption"
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|