Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dropdownlist selectedvalue

Tags:

c#

asp.net

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?

like image 583
integral100x Avatar asked May 10 '11 20:05

integral100x


People also ask

How do I pass a dropdown value to a controller?

If you want to pass the selected value of your dropdown list into your controller, just add a string parameter with the name drpFields (same as the first parameter of your DropDownList method) into your temp action method.

What is selected value in DropDownList?

The value of the selected element can be found by using the value property on the selected element that defines the list. This property returns a string representing the value attribute of the <option> element in the list. If no option is selected then nothing will be returned.

Has a SelectedValue which is invalid because it does not exist in the list of items?

Most likely causes: DropDownList has no items because the evaluation happens before the list gets bound. The list is bound but is missing this particular value. The value returned could be null.


2 Answers

Try using ddlCountry.SelectedItem.Value instead.

like image 167
Bala R Avatar answered Sep 29 '22 07:09

Bala R


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

like image 40
TheGeekYouNeed Avatar answered Sep 29 '22 07:09

TheGeekYouNeed