unable to get dropdownlist selected index value?
ON ASPX PAGE ,I have one dropdownlist box and one text box. I have added two items in dropdownlist.
Program
Batchyear
On selected index changeded event, if I select l开发者_C百科istitem Program
, I want the textbox to show
your program code is:134
.
If I select listitem Batchyear
, I want the textbox to show
your batch year is 2011
.
I write code in cs page
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" ;
}
}
It is not working. Please help.
Your dropdown list has to have the property AutoPostback=true to fire off the SelectChanged event
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
精彩评论