CS 页面
public partial class Themaes :PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    public void ThemeChanged(object sender, EventArgs e)
    {
        if (this.UserEntity != null)
        {
            this.UserEntity.theme = byte.Parse(this.DropDownList1.SelectedValue);
        }
        else
        {
            Session["Theme"] = byte.Parse(this.DropDownList1.SelectedValue);
        }
        Response.Redirect(Request.RawUrl);
    }
}源页面
 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ThemeChanged">
            <asp:ListItem Value="1">请选择</asp:ListItem>
            <asp:ListItem Value="2">绿</asp:ListItem>
            <asp:ListItem Value="3">红</asp:ListItem>
        </asp:DropDownList><br />每次我选择完颜色.这个DropDownList的选项又跳回"请选择"这个选项去了.
不明白。大家给解释下

解决方案 »

  1.   

    问题出在这里
        Response.Redirect(Request.RawUrl);
      

  2.   

    把Response.Redirect(Request.RawUrl);这个注释掉
      

  3.   

    注释了那句话。选项到是不再停留在“请选择”上了。不过选择的结果就不正确了。因为。我要在GLOBAL里面判断SESSION。
      

  4.   

    写错了不是GLOBAL。 是我页面继承的类
     protected override void OnPreInit(EventArgs e)
        {
            if (Session["Theme"] == null)
                Session["Theme"] = byte.Parse(ConfigurationManager.AppSettings["DefaultTheme"].ToString());
                
            if (Session["Language"] == null)
                Session["Language"] = ConfigurationManager.AppSettings["DefaultLanguage"].ToString();
                      
            this.theme = (byte)Session["Theme"];
            this.language = (string)Session["Language"];        if (Session["UserEntity"] != null)
            {
                this.UserEntity = (UserEntity)Session["UserEntity"];
                Session["Language"] = this.UserEntity.language;
                Session["Theme"] = this.UserEntity.theme; 
                this.theme = this.UserEntity.theme;
                this.language = this.UserEntity.language;
            }
            //页面中调用的CSS样式来源此。
            Context.Response.Write("<link href='App_Themes/Theme" + this.theme.ToString() + "/css/main.css' rel='stylesheet' type='text/css'>");
                   base.OnPreInit(e);
        }
      

  5.   

    加个参数吧.Response.Redirect("aa.aspx?theme="+this.this.DropDownList1.SelectedValue);然后page_load中设置ddl选中的初始值.
      

  6.   

    TO cpp2017(慕白兄: 你是说把Response.Redirect(Request.RawUrl);换成
    Response.Redirect("aa.aspx?theme="+this.this.DropDownList1.SelectedValue);
    然后在
    page_load中指定初始值.
      

  7.   

    这样好象不能在动态的获取SESSION里面保存的THEME了吧。全部都在page_load指定了
      

  8.   

    改完。选项又变成定死在第一个了
    不会吧???if(!this.IsPostBack)
    {
         if(Request.QueryString("theme")!=null)
         {
               ddl.selectedValue = .... //最后先判断一下合法性.
         }
    }
      

  9.   

    protected void Page_Load(object sender, EventArgs e)
        {
                   if (!this.IsPostBack)
            {
                if (Request.QueryString["Theme"] == null)
                {
                    DropDownList1.SelectedValue = "1";
                }
            }    }
        public void ThemeChanged(object sender, EventArgs e)
        {
            if (this.UserEntity != null)
            {
                this.UserEntity.theme = byte.Parse(this.DropDownList1.SelectedValue);
            }
            else
            {
                Session["Theme"] = byte.Parse(this.DropDownList1.SelectedValue);
            }
           //Response.Redirect(Request.RawUrl);
            Response.Redirect("Themaes.aspx?Theme=" + this.DropDownList1.SelectedValue);
              }
      

  10.   

    DropDownList1.SelectedValue = "1";//这样写肯定是第一个了.
     DropDownList1.SelectedValue = Request.QueryString["Theme"];
      

  11.   

    谢谢了。弄好了。
    我想问下。这样的话。我根据每个人保存自己的颜色,取保存的SESSION[THEME]得出不是都是固定的吗/
      

  12.   

    就是。每个人有自己的颜色。甲选好红色。将SESSION里面的THEME保存到数据库中。下次读取数据库。加载的时候SESSION[THEME]就是红色。