无法获得dropdownlist选择的索引值?

时间:2011-06-17 07:41:36

标签: asp.net

在ASPX PAGE上,我有一个下拉列表框和一个文本框。我在下拉列表中添加了两项。

  1. 活动

  2. Batchyear

  3. 在选定的索引更改事件中,如果我选择列表项Program,我希望文本框显示

    your program code is:134

    如果我选择listitem Batchyear,我希望文本框显示

    your batch year is 2011

    我在cs页面中编写代码

     protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
     {
       if (ddl.SelectedIndex == 0)
       { 
         TextBox1.Text="your program code is:134" ;
       }
    
       if (ddl.SelectedIndex == 1)
       { 
          TextBox1.Text="your batch year is 2011" ;
       }
    
     }
    

    它不起作用。请帮忙。

2 个答案:

答案 0 :(得分:0)

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
     if (ddl.Selectedvalues=="Program")
        TextBox1.Text="your program code is:134" ;
     if (ddl.Selectedvalues=="Batchyear")
        TextBox1.Text="your batch year is 2011" ;


}

DropDown auto Postback True

答案 1 :(得分:0)

您的下拉列表必须具有属性AutoPostback = true才能触发SelectChanged事件