Someone asked
(1) autopostback = "true"
< ASP: dropdownlist ID = "Dropdownlist1" Runat = "Server" Autopostback = "True" > </ ASP: dropdownlist >
(2) The event is also registered.
This . Dropdownlist1.selectedindexchanged + = New System. eventhandler ( This . Dropdownlist1_selectedindexchanged );
(3) the event is also written.
Private Void Dropdownlist1_selectedindexchanged ( Object Sender, system. eventargs E)
{
Response. Write (This. Dropdownlist1.selecteditem );
}
Why can't I output the selected items? Debugging finds that the selectedindexchanged event cannot be entered.
In fact, another possibility is that you set the same value for different options in dropdownlist.
For example, write in the background:
If ( ! Ispostback)
{
For ( Int I = 0 ; I < 10 ; I ++ ) This . Dropdownlist1.items. Add ( New Listitem (I. tostring (), " Same_value " ));
}
This will not trigger the selectedindexchanged event and change it
If ( ! Ispostback)
{< br> for ( int I = 0 ; I 10 ; I ++ ) This . dropdownlist1.items. add ( New listitem (I. tostring (), I. tostring ();
}
Everything is normal. According to msdn:
Listcontrol. selectedindexchanged event
When the selected items of the list control change between the information sent to the server
This is different from the onchange event in Js.
If ( ! Ispostback)
{
For ( Int I = 0 ; I < 10 ; I ++ ) This . Dropdownlist1.items. Add ( New Listitem (I. tostring (), " Same_value " ));
This . Dropdownlist1.attributes. Add ( " Onchange " , " Alert ('test '); " );
}
Test.