简体   繁体   English

如何获得下拉列表中所选项目的价值?

[英]how to get value of a selected Item in drop down list?

I need to select values from selected item in a drop down list in asp.net. 我需要从asp.net的下拉列表中的选定项目中选择值。 in this code: 在此代码中:

protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
    int index = Convert.ToInt32(EducationFeildsList.SelectedIndex);
    Label1.Text = index.ToString(CultureInfo.InvariantCulture);
}

But it seems that the value could not be read and so label1.text wasn't changed. 但是似乎无法读取该值,因此label1.text未被更改。 how I could get the correct value of a selected item in this situation? 在这种情况下,如何获取所选项目的正确值?

protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
  If (!IsPostback)
   {
    Label1.Text = Dropdownlist1.Selectedvalue;
   }
}

Set AutoPosback prperty of DDL to TRUE 将DDL的AutoPosback属性设置为TRUE

Use the Parse 使用解析

protected void EducationFeildsList_SelectedIndexChanged(object sender, EventArgs e)
{
int index = int.Parse(EducationFeildsList.SelectedIndex);
Label1.Text = index.ToString(CultureInfo.InvariantCulture);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM