Combobox Id

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
 
C

Curt_C [MVP]

Combo box or DropDownList?
should be
this.DropDownList1.SelectedItem.Value
or
this.DropDownList1.SelectedItem.Text
 
B

Big E

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
 
J

Justin Beckwith

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top