Combobox Id

  • Thread starter Thread starter Big E
  • Start date Start date
B

Big E

I'm using VB in ASP.Net with SQL Server 2000.

I have a States Combobox that lists the State. The State has a StateId in
table states. When I do updates to various tables from the form I would like
to update the StateId not the StateName. I've looked at the datamember and
datavalue stuff but don't understand it.

Can anyone point me at a sample or some code they've used.

Thanks.

Big E
 
Combo box or DropDownList?
should be
this.DropDownList1.SelectedItem.Value
or
this.DropDownList1.SelectedItem.Text
 
Actually. When I try and retrieve the contents of the dropdownlist later the
Value has the equivalents of the text. When I loaded it with data in a loop
the value was 1 where the text was Alabama. Now later they both contain
Alabama.

Thanks.

Big E


TextBox1.Text = cboStateCompany.SelectedItem.Value

TextBox2.Text = cboStateCompany.SelectedItem.Text
 
Hey Big E,
the DataTextField and DataValueField properties of the dropdownlist
are actually pretty simple. In your states table, I am assuming you
have 2 rows. The stateID and the stateName. At design time, you want
to make the DataTextField of your dropdown "stateName", and your
DataValueField "stateID". When the form submits, you can simply look
at the value of the dropdownlist, and it should be the stateID. Hope
this helps!
 
Back
Top