我的一个页面里面有下拉列表框,然后还有一组Radiobutton,如此启用radiobutton的autopostbak属性,就能在后台获取到radiobutton选中的是哪个,但也因为autopostbak会造成选择时的页面刷新,一旦刷新则下拉列表框的值就会恢复到默认值,相当白选择了,请问这种情况下我应该如何处理?谢谢

解决方案 »

  1.   

    下拉列表的EnableViewSate设为True
      

  2.   

    将根据单选框改变是需要刷新的控件(如很多则自己定个策略)放入UpdatePanel中,并设定触发条件
      

  3.   

    page_load()
    {
       if(!Ispostback)
       {}
    }
      

  4.   

    你用的RadioButtonList还是RadioButton?
      

  5.   

    如果AutoPostBack设为True的话,在Page_Load时,首先记录一下selectedIndex,如果是动态绑定的RadioButtonList的内容的话。
    先纪录下selectedIndex.再重新绑定RadioButtonList,然后将RadioButtonList的SelectIndex设为纪录下的值。
     protected void Page_Load(object sender, EventArgs e)
        {
            //纪录下选中的索引
            int selectedIndex = RadioButtonList1.SelectedIndex;        //绑定RadioButtonList
            //....        //將页面选中的索引重引设置给RadioButtonList
            RadioButtonList1.SelectedIndex = selectedIndex;
        }
    以上代码只提供一个思路。看你情况而定
      

  6.   

            protected void Page_Load(object sender, EventArgs e)
        {      if (!this.Page.IsPostBack)
            {
                this.DropDownList1.SelectedIndex = 0;//设置下拉列表的初始值
            }
    }
      

  7.   

    只要把radiobutton 放在UpdatePanel里面就可以了,已经测试过了,能实现你要的功能。