简体   繁体   English

dropdownlist selectedvalue

[英]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. 我已经使用web服务创建了一个国家/地区的下拉列表,我正在尝试将下拉列表选项添加到sql数据库中,但是当我在insert语句中使用ddlCountry.SelectedValue执行此操作时,只有下拉列表中的第一个值是出现在桌子上。 Should I use onselectedindexchanged to somehow store the value? 我应该使用onselectedindexchanged以某种方式存储值吗? What code should I be using? 我应该使用什么代码?

请尝试使用ddlCountry.SelectedItem.Value

You need to make sure you're not repopulating your dropdown from the web service on a postback. 您需要确保在回发时不从Web服务重新填充下拉列表。 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 如果你在点击按钮上发出某种保存功能,那么你可以继续使用ddl.SelectedItem.Text(如果你不想将文本存储在你的表中),如果你想存储国家列表的值部分然后继续使用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 如果要在用户选择下拉列表中的项目时执行某些操作,则仅应使用SelectedIndexChanged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM