You need to set the DataTextField property for the
DropDownList control.
Switch to the HTML view of your web form and set the
DataTextField property to the name of the column you want
the DropDownList to display.
So, if you want to display a list of say, offices, it
would look something like this:
(assumming i selected the office_name and office_id
columns from my database into my DataReader)
<asp:dropdownli st id="ddlOffices " runat="server"
datatextfield=" office_name"
datavaluefield= "office_id" ></asp:dropdownlis t>
I've also set the DataValueField property above. This is
very handy cos it means when a user selects an office from
the drop down, you can easily find the corresponding id
for the selected office and pass it to your insert/update
statements.
-----Original Message-----
Hi everyone,
Can anyone see a problem with this code. I'm kinda new to
asp.net andI'm having a problem populating a drop down list with a
database query.The results of my query populate the list with the words
"System.Data.C ommon.DbDataRec ord"
This is my code:
If Not Page.IsPostBack Then
Dim cn As New
SqlConnection( ConfigurationSe ttings.AppSetti ngs
("CONN_STRING") ) Dim sql As String = "SELECT * FROM teams "
Dim dr As SqlDataReader
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
dr = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
ddlTeam.DataSou rce = dr
ddlTeam.DataBin d()
cn.Close()
End If
Any help would be greatly appreciated.
Thanks
Rob
*** Sent via Developersdex http://www.developersdex.com
***Don't just participate in USENET...get rewarded for it!
.