有两个dropdownlist属于联动的,从数据库捞值的。
是个注册页面,问题在提交后如输入有误,dropdownlist就恢复默认的第一个值了,如何让之前选取的依然没变动。
是个注册页面,问题在提交后如输入有误,dropdownlist就恢复默认的第一个值了,如何让之前选取的依然没变动。
解决方案 »
- 三层的问题.
- Page.ClientScript.RegisterStartupScript为什么不弹出对话框呀?
- 如何释放XmlDocument对象
- 页面打印问题,关于ExecWB的设置.
- ASP.aspx程序运行后在IE显示是空白页面
- 请问asp高手和asp.net高手一个问题 !
- 谁看过孟子的利用ASP.NET DataGrid显示主次关系的数据文章
- 各位大侠看看对象数组是不是这么用的!?!!!!!!????????????????
- 为什么当IIS的ip绑定后,在vs.net里便不能创建asp.net项目?
- 有没有免费的ASP.NET空间?
- fckeditor运行后是html代码
- 急。在线等。马上给分 如何将网页地址简单化到输入IP或域名即可
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
//测试数据
String[] A = { "A", "B", "C" };
Hashtable b = new Hashtable(); protected void Page_Load(object sender, EventArgs e)
{
b.Add("A", "A1:A2");
b.Add("B", "B1:B2");
b.Add("C", "C1:C2");
if (!Page.IsPostBack)
{
DropDownList1.DataSource = A;
DropDownList1.DataBind();
DropDownList2.DataSource = b["A"].ToString().Split(':');
DropDownList2.DataBind();
} } protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(DropDownList1.SelectedValue + ":" + DropDownList2.SelectedValue);
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.DataSource = b[DropDownList1.SelectedValue].ToString().Split(':');
DropDownList2.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
</body>
</html>
那么你选择一次,他页面刷新一次,dropdownlist重新填充一次,他肯定不会停留在你第一次选择的那个value上。Page_Load事件下面加上 if (!Page.IsPostBack)
然后在这个if下面写实现过程。
比如一个注册页面,如果说你填写的用户名重复,那肯定不能通过验证,那么这个时候两个dropdownlist的都默认选择到第一个value上了,我是求如果没通过验证让他保持之前选项不变的方法~
{
if (!IsPostBack)
{
ddlMedia.SelectedIndex = Convert.ToInt32(Session["mediaIndex"]);
ddlQuarter.SelectedIndex = Convert.ToInt32(Session["quarterIndex"]);
}
} protected void Button1_Click(object sender, EventArgs e)
{
//if(验证失败)
Session["mediaIndex"] = ddlMedia.SelectedIndex;
Session["quarterIndex"] = ddlQuarter.SelectedIndex;
Response.Redirect("~/WebForm1.aspx");
}ession存起来,然后在回发的过程中重新设置就行啦