保留回发后动态绑定的DropDownList的选定值 [英] Retain Selected Value of dynamically bound dropdownlist after postback
本文介绍了保留回发后动态绑定的DropDownList的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的ASPX标记声明,像这样一个DropDownList:
I have a dropdownlist which I declare on the aspx markup like so:
<asp:DropDownList ID="State" runat="server"></asp:DropDownList>
然后我将它绑定在页加载像这样:
Then I bind it on page load like so :
protected void Page_Load(object sender, EventArgs e)
{
BindDropdowns();
}
private void BindDropdowns()
{
State.DataSource = DataAccess.GetStates();
State.DataValueField = "FieldId";
State.DataTextField = "FieldName";
State.DataBind();
}
选择的值不回发后保留下来,我也可以不火的selectedindexchangedevent。怎么了?
The selected value is not retained after postback, I also cannot fire the selectedindexchangedevent. What's wrong ?
推荐答案
请改变你的code是这样的:
please change your code like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostback)
BindDropdowns();
}
这意味着,在第一次页面加载你的下拉控件只能被绑定一次,
This means that your dropdown control is only bound once on first pageload
这篇关于保留回发后动态绑定的DropDownList的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文