updatapanel 保存中如何保存dropdownlist的选定的值

来源:百度知道 编辑:UC知道 时间:2024/07/07 21:04:24
我在用户控件ascx中加入了一个updatapanel

并在里面加入了一个下拉列表.跳转到另一个页面怎么保存下拉列表选择的值? 我现在跳转后下拉列表还是选择的默认值.
代码如下:

head.ascx用户控件

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableViewState=true />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState=true>
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" EnableViewState=true>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>

test.aspx后台代码中再重新指定DropDownList的选定项:
this.DropDownList1.SelectedIndex = Convert.ToInt32(Session["test"]));

Response.Redirect("test.aspx?test1="+Convert.ToString(Session["test"]));
接收时:
在page_load()
{
this.GridView.SelectedValue=Request["test1"].ToString();
}

检查你的数据绑定是否在
if(!this.IsPostBack){}
之内

在page_load中数据绑定要判断IsPostBack,这样每次提交都不会重新赋值了

难道是没有加if(!postback)的问题?