c# - Dynamically created dropdowns and fired events accordingly -


i have simple task. first 1 dropdownlist control there country name loaded. after selecting country name, dynamically dropdownlist loaded corresponding state, after selecting state, dynamically dropdownlist added relevant district. problem dynamically selected-index event not fired. searched many pages, not find suitable answer. can 1 answer written code.

this code worked fine in static controls. not dynamic controls. can 1 correct code

namespace fireprogram  {     public partial class mindforesystemtestingprogram : system.web.ui.page     {       balayer objbalayer = new balayer();       dropdownlist ddlstate=new dropdownlist();       dropdownlist ddldistrict=new dropdownlist();     protected void page_init(eventargs e)     {         ddlstate.id = "ddlstate";         ddlstate.autopostback = true;         ddlstate.selectedindexchanged += new eventhandler(ddlstate_selectedindexchanged);         panel1.controls.addat(2, ddlstate);           ddldistrict.id = "ddldistrict";         panel1.controls.addat(3, ddldistrict);           }     protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             ddlcountry.datasource = objbalayer.getcountry();             ddlcountry.datatextfield = "text";             ddlcountry.datavaluefield = "value";             ddlcountry.databind();         }         //else         //{                       //    ddlstate.id = "ddlstate";         //    ddlstate.autopostback = true;         //    ddlstate.selectedindexchanged += new eventhandler(ddlstate_selectedindexchanged);         //    panel1.controls.addat(2, ddlstate);           //    //ddldistrict.id = "ddldistrict";         //    //panel1.controls.addat(3, ddldistrict);         //}     }      protected void ddlcountry_selectedindexchanged(object sender, eventargs e)     {                     int value = convert.toint32(ddlcountry.selectedvalue);                    panel1.controls.addat(2, ddlstate);         //dropdownlist ddlstate = new dropdownlist();                                        //ddlstate.autopostback = true;         if (value != 0)         {             ddlstate.datasource = objbalayer.getstate(value);             ddlstate.datatextfield = "text";             ddlstate.datavaluefield = "value";             ddlstate.databind();         }                           }        protected void ddlstate_selectedindexchanged(object sender, eventargs e)     {         int value = convert.toint32(ddlstate.selectedvalue);                    //dropdownlist ddldistrict = new dropdownlist()         panel1.controls.addat(3, ddldistrict);         if (value != 0)         {             ddldistrict.datasource = objbalayer.getdistrict(value);             ddldistrict.datatextfield = "text";             ddldistrict.datavaluefield = "value";             ddldistrict.databind();         }     } } 

}


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -