Filling a Drop Down List Box Properly

a02227

Member
Joined
Nov 30, 2004
Messages
15
Location
Ireland
Programming Experience
Beginner
I have a Drop Down List Being filled by a table in a database however it only seems to be filling the box with on field in the box i.e. putting individual letters of the first field all the way down the box does anyone know whats wrong?

Heres the code i'm filling the box with: -

OleDbDataAdapter1.fill(DataSet11.Location)
DropDownList1.DataBind
DropDownList1.DataSource = DataSet11.Location()
DropDownList1.DataMember = "Location"

Can anyone help me with this, i'm sure its probably something simple
 
I have State table in my database. I filled my dropdownlist with my states:

Function MyQueryMethod() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\"yourdatabasefileName".mdb"

Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)



Dim queryString As String = "SELECT [State].[State_Abbreviate] FROM [State]"

Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand

dbCommand.CommandText = queryString

dbCommand.Connection = dbConnection



Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter

dataAdapter.SelectCommand = dbCommand

Dim dataSet As System.Data.DataSet = New System.Data.DataSet

dataAdapter.Fill(dataSet)

Return dataSet

End Function

Then in Page_load even
If Not Page.IsPostBack Then

DropDownList1.DataTextField = "State Abbreviate"

DropDownList1.DataSource = MyQueryMethod()

DropDownList1.DataBind()



End If

 
Back
Top