dynamic control (c# ASP.net)
-
hi I have created one method createdropdown()in that i had create one dynamic dropdownlist and in selectindexchange of that dropdownlist i had created another dynamic dropdownlist and again selectedindexchange of the second dropdown . but when i run this code it will call first selectedindexchange when i select the dropdownvalue but it want call second selectedindexchange. i had done autopostBack=true for both the dropdownlist. Please Help It is some urgent Task that i have to complet. in the below ddl_SelectedIndexChanged() is call but ddl2____SelectedIndexChanged is not fired.....? // Add DropDownList Control to Placeholder private void CreateDropDownBoxes() { //int counter= Convert[ViewState ("counter"),Int32]; for (int counter = 0; counter <= NumberOfControls; counter++) { DropDownList ddl = new DropDownList(); ddl.ID = "DropDownList_ID" + (counter + 1).ToString(); ddl.AutoPostBack = true; ddl.AppendDataBoundItems = true; ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); DataTable dt = new DataTable(); dt = getdata_workspace(); ddl.DataSource = dt; ddl.DataTextField = "displayedname"; ddl.DataValueField = "id"; ddl.DataBind(); phDropDownLists.Controls.Add(ddl); phDropDownLists.Controls.Add(new LiteralControl(" ")); } } public void ddl_SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) { SqlConnection conn = new SqlConnection(connStr); string boxName = "DropDownList_ID" + (i + 1).ToString(); DropDownList ddl2_ = phDropDownLists.FindControl(boxName) as DropDownList; DropDownList ddl2___ = new DropDownList(); ddl2___.ID = "DropDownList__" + (i + 1).ToString(); ddl2___.AutoPostBack = true; ddl2___.AppendDataBoundItems = true; ddl2___.EnableViewState = true; SqlCommand cmd = new SqlCommand("select * from unit where workspaceid='" + ddl2_.SelectedValue + "'", conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ddl2___.Items.Add(dr.GetString(2)); } // ddl2___.EnableViewState = true; ddl2___.SelectedIndexChanged += new EventHandler(ddl2____SelectedIndexChanged); ddl2___.DataTextField = "displayedname"; ddl2___.DataValueField = "id"; phTextBoxes.Controls.Add(ddl2___); phTextBoxes.Controls.Add(new LiteralControl(" ")); } // throw new Exception("The method or operation is not implemented."); } void ddl2____SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) {
-
hi I have created one method createdropdown()in that i had create one dynamic dropdownlist and in selectindexchange of that dropdownlist i had created another dynamic dropdownlist and again selectedindexchange of the second dropdown . but when i run this code it will call first selectedindexchange when i select the dropdownvalue but it want call second selectedindexchange. i had done autopostBack=true for both the dropdownlist. Please Help It is some urgent Task that i have to complet. in the below ddl_SelectedIndexChanged() is call but ddl2____SelectedIndexChanged is not fired.....? // Add DropDownList Control to Placeholder private void CreateDropDownBoxes() { //int counter= Convert[ViewState ("counter"),Int32]; for (int counter = 0; counter <= NumberOfControls; counter++) { DropDownList ddl = new DropDownList(); ddl.ID = "DropDownList_ID" + (counter + 1).ToString(); ddl.AutoPostBack = true; ddl.AppendDataBoundItems = true; ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); DataTable dt = new DataTable(); dt = getdata_workspace(); ddl.DataSource = dt; ddl.DataTextField = "displayedname"; ddl.DataValueField = "id"; ddl.DataBind(); phDropDownLists.Controls.Add(ddl); phDropDownLists.Controls.Add(new LiteralControl(" ")); } } public void ddl_SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) { SqlConnection conn = new SqlConnection(connStr); string boxName = "DropDownList_ID" + (i + 1).ToString(); DropDownList ddl2_ = phDropDownLists.FindControl(boxName) as DropDownList; DropDownList ddl2___ = new DropDownList(); ddl2___.ID = "DropDownList__" + (i + 1).ToString(); ddl2___.AutoPostBack = true; ddl2___.AppendDataBoundItems = true; ddl2___.EnableViewState = true; SqlCommand cmd = new SqlCommand("select * from unit where workspaceid='" + ddl2_.SelectedValue + "'", conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ddl2___.Items.Add(dr.GetString(2)); } // ddl2___.EnableViewState = true; ddl2___.SelectedIndexChanged += new EventHandler(ddl2____SelectedIndexChanged); ddl2___.DataTextField = "displayedname"; ddl2___.DataValueField = "id"; phTextBoxes.Controls.Add(ddl2___); phTextBoxes.Controls.Add(new LiteralControl(" ")); } // throw new Exception("The method or operation is not implemented."); } void ddl2____SelectedIndexChanged(object sender, EventArgs e) { int n = this.NumberOfControls; for (int i = 0; i < n; i++) {
advice 1:do not post whole project in the forum, its irritating, only post the code which u feel as doubtful. advice 2: ur naming convention according to the above code is very very bad. (such as ddl___SelectIndex...). dude:if u wanna quick result for ur problem, follow the advice.:zzz:
Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)