I've used a webservice to create a d开发者_开发百科ropdownlist 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?
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 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
精彩评论