Databound Dropdownlist....

  • Thread starter Thread starter Scott D
  • Start date Start date
S

Scott D

I have a databound dropdown list that is using a SQL database to pull
an ID field (CVID) as the Value and a name field (ContractVehicle) as
the Text. The dropdown populates perfectly from the database however
when I attempt to submit the selection to the database using
me.ddPMID.DataValueField I receive an error saying that string "CVID"
cannot be converted to type integer. The Value field should contain
integers as each of them are autonumbered by the database. The code I
am using to populate the dropdownlist follows. Any help would be
greatly appreciated.

Dim connString As String =
"server=192.168.25.245;uid=sa;pwd=nuts@sigcom!-1;Initial
Catalog=SIGCOMproposal"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim sql As String = "SELECT * FROM tblContractVehicle ORDER BY
ContractVehicle"
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet()

da.Fill(ds, "tblContractVehicle")
Dim dt As DataTable
dt = ds.Tables(0)
dt.DefaultView.Sort = "ContractVehicle"
Me.ddCVID.DataSource = dt.DefaultView
Me.ddCVID.DataTextField = "ContractVehicle"
Me.ddCVID.DataValueField = "CVID"
Me.ddCVID.DataBind()
Me.ddCVID.Items.Insert(0, "--Select a Contract Vehicle--")
Me.ddCVID.Items(0).Value = "0"

conn.Close()
 
Sorry. ddPMID should actually be ddCVID in the post. I tried using
me.ddCVID.SelectedIndex.Value however value is not a property of
SelectedIndex unless I am missing something.
 
Back
Top