c# - dropdown SelectedIndexChanged event is not triggering if index is changed in page_load event -
i have drop down & label, drop down binded dictionary. when user changes selected value of drop down want update label. following code works want set initial value of label, set value of selected index in page_load, event not trigger. how fix it? there page event can me solve issue. know can fix using javascript not want use js.
public partial class webform1 : system.web.ui.page { dictionary<string, string> mydictionary = new dictionary<string, string>(); protected void page_load(object sender, eventargs e) { if (!this.ispostback) { mydictionary.add("1", "test address 1"); mydictionary.add("2", "test address 2"); mydictionary.add("3", "test address 3"); mydictionary.add("4", "test address 4"); mydictionary.add("5", "test address 5"); drptest.datasource = mydictionary; drptest.datatextfield = "key"; drptest.datavaluefield = "value"; drptest.databind(); // want set index & update label lbladdress drptest.selectedindex = 2; } } protected void drptest_selectedindexchanged(object sender, eventargs e) { lbladdress.text = drptest.selecteditem.value; }
you should call function @ page load
drptest_selectedindexchanged(null, null)
and doesn't trigger normal because didn't change dropdown selected value after initializing page , ready used client
Comments
Post a Comment