asp.net保管箱值“固定"到零索引 [英] asp.net dropbox value 'sticks' to zero index
本文介绍了asp.net保管箱值“固定"到零索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,标题说明了一切,
而且我不是基于Web的开发的英雄
我在page_load填充了一个字典:
well, the title says it all,
and i am not a hero with webbased development
i got an dictionary thats been filled at the page_load :
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<int, string> values = new Dictionary<int, string>();
values.Add(0, "Value1");
values.Add(1, "Value2");
//crebotbox is a dropdownbox
Crebotbox.DataSource = values;
Crebotbox.DataTextField = "Value";
Crebotbox.DataValueField = "Key";
Crebotbox.DataBind();
}
并且其设定值必须与字符串查询一起传递到下一页
and its suposed value must pass with the string query through the next page
protected void submitbtn_Click(object sender, EventArgs e)
{
Response.Redirect(string.Format("~/testpage.aspx?curnmr={0}&crb={1}", Curnmrtbox.Text, Crebotbox.SelectedItem.Value));
}
但无论我在页面本身上选择哪个值,它都会不断推动Dropbox的第一个值
我曾尝试切换Autopostback属性,但这是徒劳的.
but no matter wich value i select on the page itself, it just keeps pushing the first value of the dropbox
i have tried switching the Autopostback atribute but that was fruitless.
does someone have an idea?
推荐答案
更正了您的代码....
Corrected your code....
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<int,> values = new Dictionary<int,>();
values.Add(0, "Value1");
values.Add(1, "Value2");
//crebotbox is a dropdownbox
if(!Page.IsPostback)
{
Crebotbox.DataSource = values;
Crebotbox.DataTextField = "Value";
Crebotbox.DataValueField = "Key";
Crebotbox.DataBind();
}
}
这篇关于asp.net保管箱值“固定"到零索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文