日期:2014-05-17  浏览次数:20580 次

ASP.NET DropdownList显示问题
DropdownList的AutoPostBack属性初始是true,我在SelectedIndexChanged中做某判断,不符合条件时给一个提示,然后将SelectedIndex值赋为0(text值为--请选择--),为什么在页面中的选项没变过来?

  protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)  
  {
  if (不符合条件)
  {
  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "message", "alert('****')", true);
  DropDownList2.AutoPostBack = false;//防止重新触发SelectedIndexChanged事件
  DropDownList2.SelectedIndex = 0;
  DropDownList2.AutoPostBack = true;
  return;
  }
  }

------解决方案--------------------
还有这样的需求?

1 DropDownList2.AutoPostBack = false;//防止重新触发SelectedIndexChanged事件
 2 DropDownList2.SelectedIndex = 0;
3DropDownList2.AutoPostBack = true;


1 你设置了false 那么2 还会回发么?




------解决方案--------------------
还有就是你在DropDownList2_SelectedIndexChanged中“//防止重新触发SelectedIndexChanged事件”

本身就已经在SelectedIndexChanged中,逻辑有错误把
------解决方案--------------------
我猜你是在加载事件里对DropDownList绑定了值,但是没放在 if(!ispostback){}里面