integral100x
integral100x

Reputation: 342

dropdownlist selectedvalue

I've used a webservice to create a dropdownlist of countries and I'm trying to add the dropdownlist selection to the sql database, but when I do that by using ddlCountry.SelectedValue in my insert statement, only the first value in the dropdownlist is showing up in the table. Should I use onselectedindexchanged to somehow store the value? What code should I be using?

Upvotes: 5

Views: 34327

Answers (3)

Kunal
Kunal

Reputation: 1943

If you are firing some sort of save function on button click's even then you can go ahead with ddl.SelectedItem.Text (if you wan't to store the text in your table) if you want to store the value part of the country list then go ahead with ddl.SelectedItem.Value

SelectedIndexChanged should be only used if you want to perform some action at the time when user selects an item in the drop down

Upvotes: 0

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

You need to make sure you're not repopulating your dropdown from the web service on a postback. That will cancel out your selection.

Upvotes: 1

Bala R
Bala R

Reputation: 108937

Try using ddlCountry.SelectedItem.Value instead.

Upvotes: 10

Related Questions