dropdownlist选择的值使我感到困惑吗? [英] dropdownlist selected value confused me?
问题描述
嘿
从下拉列表中选择组时,我有asp.net页面下拉列表和按钮
然后单击按钮,然后按钮通过查询字符串发送所选值(组ID)
然后根据查询字符串中的ID进行页面浏览组详细信息,这是第一次发生
但是当我从下拉列表更改组时,查询字符串仍然具有最后一个ID
和我的代码
hey
i have asp.net page dropdownlist and button when choose my group from dropdownlist
and click button then button send selected value (group-id) via query string
then page view group detail based on id in query string this happens the first time
but when i change group from dropdownlist the query string still has the last id
and my code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) FillList();
if (Request.QueryString["id"] != null)
{
FillData();
div_General.Visible = true;
div_Special.Visible = true;
dropdownlist1 .SelectedValue = Request.QueryString["id"];
}
}
protected void button1_Click(object sender, EventArgs e)
{
if (dropdownlist1 .SelectedIndex== 0)
{
par_ErrorMessage.InnerText = "choose group first ...";
par_ErrorMessage.Visible = true;
}
else Response.Redirect("Authority.aspx?id=" + dropdownlist1.SelectedValue);
}
当我单击按钮并假设
中的新值时,我想到了这个问题
dropdownlist页面生命周期首先转到页面加载,并且在此代码中
i figured the problem in this when i click button and suppose that new value in
dropdownlist page life cycle go to page load first and in this code
dropdownlist1 .SelectedValue = Request.QueryString["id"];
从button1_click
读取之前,将所选值返回到最后一个值
请帮助我
return selected value to the last one before read it from button1_click
plz i need help
推荐答案
您可以为页面加载事件后的下拉列表选择值
You can Select Value for Drop Down after Page Load Event
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillList();
Viewstate["id"] = Request.QueryString["id"];
if (Request.QueryString["id"] != null)
{
FillData();
div_General.Visible = true;
div_Special.Visible = true;
}
}
}
现在,在Page_PreRender中,您可以在下拉菜单中选择值",如下所示:-
Now in Page_PreRender you can Select Value in dropdown like this:-
protected void Page_PreRender(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
if (ViewState["id"] != null)
{
dropdownlist1 .SelectedValue = ViewState["id"].ToString();
}
}
}
通过Rahul om stackoverflow
via Rahul om stackoverflow
这篇关于dropdownlist选择的值使我感到困惑吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!