单击提交按钮后,不会保留下拉列表选定值 [英] Dropdown selected value not retained after the submit button click

查看:195
本文介绍了单击提交按钮后,不会保留下拉列表选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个下拉菜单选择任务和其他选择子任务....当我选择基于所选任务类别的子任务时,它保留在下拉列表...为此我将ViewStateMode更改为启用....当我点击我的提交按钮时,它从子任务下拉列表获取第一个值,并使用这些值填充数据库....



taskDrpDown- ViewStateMode:启用自动回复:True

subTaskDrpDown - ViewStateMode:启用AutopostBack:False



page_load还有(!IsPostback){// code}



populateCategory {// code}



taskDrpDown_SelectedIndexedChanged {// populateSubCategory}



populateSubCategory {// code}



submit_click {//将所有条目提交到数据库的代码}



我在回发的地方出错了所有..... ??



请帮助!!



提前致谢!

I have two dropdowns select task and other select sub task....when i select sub task based on the selected task category it retains on the dropdown...for that i changed the ViewStateMode to enabled....However when i click on my submit button it takes the first value from the sub task dropdown and fills the database with those values....

taskDrpDown- ViewStateMode: Enabled Autopostback: True
subTaskDrpDown - ViewStateMode: Enabled AutopostBack: False

also page_load has(!IsPostback){//code}

populateCategory{//code}

taskDrpDown_SelectedIndexedChanged{//populateSubCategory}

populateSubCategory{//code}

submit_click{//code to submit all the entries to database}

Am i going wrong somewhere with the postback and all.....??

Please Help!!

Thanks in advance!

推荐答案

检查你是否在提交按钮点击后将值绑定到taskDrpDown。

你的下拉列表正在反弹,因此它无法保留所选的值。



你应该只设置dropdownlist.selecteditem =以前选择的项目
check if you are binding values to taskDrpDown after submit button click.
Your drop-down list is getting rebound and hence it would not able able to retain the selected value.

you should just set the dropdownlist.selecteditem =previously selected item


把if语句放在页面加载你绑定的地方这些下拉菜单如下



if(!IsPostBack)

{

//绑定代码dropdown1

//绑定
下拉代码2

}
Put if statement on page load where you are binding these dropdowns like below

if(!IsPostBack)
{
//Bind Code of dropdown1
//Bind
Code of dropdown2
}


这篇关于单击提交按钮后,不会保留下拉列表选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆