Get value from dropdownlist

P

Przemek

Hi,

I've populated my dropdown list from database (category table) via
datatable. It's showing categories in strings. The problem appears,
when I want to add new record to database (entry_table). I'm using
stored procedures and everything works fine until I want to insert
Category ID into entry_table.

I'm getting the selected item from drop down list:

category = myDropDownList.SelectedItem.Value.ToString

and using Select Case statement I'd like to set up valid ID:

Select Case categoryValue
Case categoryValue = "Economy"
category = 1
Case categoryValue = "Politics"
category = 2
End Select

but, string from dropdownlist contains whitespace. I've tried .Trim
function but it didn't work too. Is there any solution for my problem?
Or is there any other way to get back correct IDs?

Przemek
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

The value from the dropdownlist contains exactly what you put in it when
you populate it.

What is the data type in the database? If you are using the archaic data
type char instead of varchar, it would be padded with spaces.

The value is not what is displayed in the dropdownlist. Why don't you
put the id in the value instead of the text?
 
B

Bruno Alexandre

populate the dropdown with TEXT and VALUE

TEXT is what the user will read from the dropdownlist
VALUE is the value that you'll retrieve from dropdownlist.selectedvalue

if you do not populate like this, the dropdown value = dropdown text
 

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,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top