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?
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.
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.
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.
Try using ddlCountry.SelectedItem.Value
instead.
You need to make sure you're not repopulating your dropdown from the web service on a postback. That will cancel out your selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With