我在应用程序中有一个级联的DropDownList。级联下拉列表的内容很小,因此不需要使用AJAX / JSON来访问数据库以获取内容,我只是在客户端javascript中这样做(这是数据):

var val = typeList.value;var applyTimeList = document.getElementById('clientid');for (var q=applyTimeList.options.length; q>=0; q--) applyTimeList.options[q]=null;if (val == 'AutoRoute'){ myEle = document.createElement('option') ; myEle.value = 'SOP Processed'; myEle.text = 'SOP Processed'; applyTimeList.add(myEle) ;} else if (val == 'Tier1Retention') { myEle = document.createElement('option') ; myEle.value = 'Study Processed'; myEle.text = 'Study Processed'; applyTimeList.add(myEle); myEle = document.createElement('option') ; myEle.value = 'Study Restored'; myEle.text = 'Study Restored'; applyTimeList.add(myEle); myEle = document.createElement('option') ; myEle.value = 'Study Archived'; myEle.text = 'Study Archived'; applyTimeList.add(myEle) ;}


当我尝试访问服务器端的DropDownList时,无法获取所选的值,它始终返回0作为索引:

int index = RuleApplyTimeDropDownList.SelectedIndex;


修改后如何在服务器端获取选择的值?

最佳答案

可以从DropDownList检索该值,因为在客户端添加的值将不在ViewState中。正确的方法是:

string selectedVal = Request[RuleApplyTimeDropDownList.UniqueID].

09-13 09:01