DropDownList没有正确选择值 [英] DropDownList is not selecting value properly

查看:48
本文介绍了DropDownList没有正确选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DropDownList6.Items.Add(new ListItem("sweeper", "1"));
DropDownList6.Items.Add(new ListItem("watchman", "2")); 

if (DropDownList6.SelectedValue == "1")
{
  Response.Redirect("sweeper.aspx");
}
else if (DropDownList6.SelectedValue == "2")
{
  Response.Redirect("watchman.aspx");
}    



追加数据绑定:False
自动回传:False
CausesValidation:假
已启用:True
启用主题:True
启用视图状态:True

在这里,我将第一个项目添加为"sweeper",它一直都在进行sweeper.aspx,
它始终始终仅重定向到value = 1页面...,
在编码中是否有任何错误....???



Append Data Bound :False
Auto Post Back : False
CausesValidation : False
Enabled : True
Enable Theming : True
Enable View State : True

here as i hav added first item as "sweeper" it is always going sweeper.aspx,
it is always redirecting to value=1 page only...,
is there any mistake in coding....???

推荐答案

如果您用Google搜索"DropDownList.SelectedValue",您会经常发现此问题:答案是一般情况下,以下行:加载DropDownList时是否检查过IsPostBack吗?"

你检查过了吗?因为如果您没有...
If you google for "DropDownList.SelectedValue" you will find this problem quite often: the answer is generaly allong the lines of: "Did you check IsPostBack when you loaded the DropDownList?"

Did you check? Because if you didn''t...


问题非常清楚,那么该下拉列表将始终绑定,并且默认情况下您的第一项已被选中.

所以绑定逻辑应该在!IsPostBack
The problem is very clear, that this dropdown is always binded and your first item became selected by default.

So binding logic should be in !IsPostBack


hi,解决方案2是正确的,绑定逻辑应该在!IsPostBack
Solution 2 is right,The binding logic should be in !IsPostBack


这篇关于DropDownList没有正确选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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