我需要在asp.net的下拉列表中选择所选项目的值。在这段代码中:
protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
int index = Convert.ToInt32(EducationFeildsList.SelectedIndex);
Label1.Text = index.ToString(CultureInfo.InvariantCulture);
}
但似乎无法读取该值,因此label1.text未被更改。在这种情况下,如何获得所选项目的正确值?
答案 0 :(得分:0)
protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
If (!IsPostback)
{
Label1.Text = Dropdownlist1.Selectedvalue;
}
}
答案 1 :(得分:0)
将DDL的AutoPostback属性设置为 TRUE
使用Parse
protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
int index = int.Parse(EducationFeildsList.SelectedIndex);
Label1.Text = index.ToString(CultureInfo.InvariantCulture);
}