ASP.Net我的更新值从下拉列表不更新/显示 [英] ASP.Net My Updated Value From Drop Down List Doesn't Update/Display
本文介绍了ASP.Net我的更新值从下拉列表不更新/显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这是在会话存储数据的4页ASP.NET表单。我的第3页上的按钮清除会话。所有这一切工作正常,但我有更新,因为它保留了我的确认页值的问题/显示我最初选择的值,我不能找出原因。
I have a 4 page ASP.NET form which is storing data in the session. A button on my 3rd page clears the session. All this is working fine but I'm having a problem updating a value on my confirmation page as it retains/displays my initial selected value and i cant figure out why.
第一页HTML随着DropDownList的
<asp:DropDownList ID="ddlInnoc" runat="server" class="form-control">
<asp:ListItem Value="0">- - Please Select - -</asp:ListItem>
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
</asp:DropDownList>
第一页code这将重新显示选定值的背后
protected void Page_Load(object sender, EventArgs e)
{
txtData1.Focus();
if (txtData1.Text == string.Empty && Session["pg1input"] != null)
{
txtData1.Text = Session["pg1input"].ToString();
}
if (Session["pg1dd"] != null)
{
ddlInnoc.SelectedValue = Session["pg1dd"].ToString();
}
//if (Session["pg1dd"].ToString() == "")
//{
// ddlInnoc.SelectedValue = Session["pg1dd"].ToString();
//}
}
protected void pg1button_Click(object sender, EventArgs e)
{
Session["pg1input"] = txtData1.Text;
Session["pg1dd"] = ddlInnoc.SelectedItem;
Response.Redirect("/Session/pg2.aspx");
}
第3页HTML code
<div class="form-group">
<div class="col-xs-12">
<asp:Label ID="Label1" class="col-md-2 control-label" runat="server" Text="Name:"></asp:Label>
<div class="col-md-3 form-control-static">
<%=Session["pg1input"] %>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<asp:Label ID="Label2" class="col-md-2 control-label" runat="server" Text="Sex:"></asp:Label>
<div class="col-md-3 form-control-static">
<%=Session["pg1dd"] %>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-offset-4 col-xs-12">
<asp:LinkButton ID="pg1EditButton" runat="server" OnClick="pg1EditButton_Click" CssClass="btn btn-default">
<span aria-hidden="true" class="glyphicon glyphicon-pencil"></span> Edit
</asp:LinkButton>
</div>
</div>
第3页编辑按钮code背后
protected void pg1EditButton_Click(object sender, EventArgs e)
{
Response.Redirect("/Session/pg1.aspx");
}
我怀疑它的东西与我的背后第1页的所有其他领域/单选按钮在其他页面检索和显示我的第三页上的更新值在code做的。
I suspect that its something to do with the code behind on my page 1 as all the other fields/radio buttons on the other pages retrieves and displays the updated value on my 3rd page.
推荐答案
修正为
if (!IsPostBack)
{
if (ddlInnoc.SelectedValue != "0" && Session["pg1dd"] != null)
{
ddlInnoc.SelectedValue = Session["pg1dd"].ToString();
}
}
这篇关于ASP.Net我的更新值从下拉列表不更新/显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文