Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Data Bind

Status
Not open for further replies.

asafb

Programmer
Jun 17, 2003
80
US
Hello, I'm having problems databinding a combobox.
Code:
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Function GetPriceBracket() As System.Data.DataSet
Dim connectionString As String = "server='x'; user id='sa'; password='x'; database=x"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT [pricebracket].[price] FROM [pricebracket]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function


Sub Page_Load(Sender As Object, E As EventArgs)


comboboxid.DataSource = GetPriceBracket()
comboboxid.DataBind()


End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<form runat="server">
<asp:DropDownList id="comboboxid" runat="server"></asp:DropDownList>
</form>
</body>
</html>
 
Try setting the DataTextField and DataValueField properties.

Like this:

Code:
<asp:DropDownList id="comboboxid" runat="server" datatextfield="[Field to display]" datavaluefield="[Field to use as value]"></asp:DropDownList>

or...

Code:
comboboxid.DataSource = GetPriceBracket()
comboboxid.DataTextField = "[Field To Display]";
comboboxid.DataValueField = "[Field To Use As Value]";
                   comboboxid.DataBind()

Hope that helps

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top