Dynamic Dropdown list Event (SelectedIndexChanged() ) is not firing
-
I am new to ASP.Net development in using C# In my webform there is one dropdown list called "DropDownList1". When i Select one of the items in this drpdownlist1, another dropdownlist is dynamically created called "DropdownList2". An I have to create more controls depends on the selection of "DropDownList2".But when i select DropdownList2 , its not working. ie: DropDownList_SelectedIndexChanged is not firing.Moreover the "DropDownList2" is get disappeared when i select the "DropDownList2". This is the code I have written.. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList drpDownListSender = (DropDownList)sender; string strDropDownList1ID = drpDownListSender.SelectedItem.Value; switch (strDropDownList1ID) { case "TRIN": Label SourceLabel = new Label(); SourceLabel.ID = "SourceLabel"; SourceLabel.Text = "SOURCE"; SourceLabel.Style["Position"] = "Absolute"; SourceLabel.Style["Top"] = "120px"; SourceLabel.Style["Left"] = "232px"; form1.Controls.Add(SourceLabel); DropDownList2 = new DropDownList(); DropDownList2.ID = "DropDownList2"; DropDownList2.Style["Position"] = "Absolute"; DropDownList2.Style["Top"] = "120px"; DropDownList2.Style["Left"] = "445px"; DropDownList2.AutoPostBack = true; DropDownList2.EnableViewState = true; DropDownList2.Visible = true; form1.Controls.Add(DropDownList2); DropDownList2.Items.Insert(0, "SELECT"); DropDownList2.Items.Insert(1, "CENTRAL STORE"); DropDownList2.SelectedIndexChanged += new System.EventHandler(DropDownList2_SelectedIndexChanged); break; case "TROUT": // Label4.Text = "Second Category Selected"; break; } protected void DropDownList2_SelectedIndexChanged(object sender,EventArgs e) { ViewState["DropDownList2"] = DropDownList2.SelectedValue.ToString(); TextBox TextBox3 = new TextBox(); TextBox3.ID = "TextBox3"; TextBox3.Style["Position"] = "Absolute"; TextBox3.Style["Top"] = "400px"; TextBox3.Style["Left"] = "600px";
-
I am new to ASP.Net development in using C# In my webform there is one dropdown list called "DropDownList1". When i Select one of the items in this drpdownlist1, another dropdownlist is dynamically created called "DropdownList2". An I have to create more controls depends on the selection of "DropDownList2".But when i select DropdownList2 , its not working. ie: DropDownList_SelectedIndexChanged is not firing.Moreover the "DropDownList2" is get disappeared when i select the "DropDownList2". This is the code I have written.. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList drpDownListSender = (DropDownList)sender; string strDropDownList1ID = drpDownListSender.SelectedItem.Value; switch (strDropDownList1ID) { case "TRIN": Label SourceLabel = new Label(); SourceLabel.ID = "SourceLabel"; SourceLabel.Text = "SOURCE"; SourceLabel.Style["Position"] = "Absolute"; SourceLabel.Style["Top"] = "120px"; SourceLabel.Style["Left"] = "232px"; form1.Controls.Add(SourceLabel); DropDownList2 = new DropDownList(); DropDownList2.ID = "DropDownList2"; DropDownList2.Style["Position"] = "Absolute"; DropDownList2.Style["Top"] = "120px"; DropDownList2.Style["Left"] = "445px"; DropDownList2.AutoPostBack = true; DropDownList2.EnableViewState = true; DropDownList2.Visible = true; form1.Controls.Add(DropDownList2); DropDownList2.Items.Insert(0, "SELECT"); DropDownList2.Items.Insert(1, "CENTRAL STORE"); DropDownList2.SelectedIndexChanged += new System.EventHandler(DropDownList2_SelectedIndexChanged); break; case "TROUT": // Label4.Text = "Second Category Selected"; break; } protected void DropDownList2_SelectedIndexChanged(object sender,EventArgs e) { ViewState["DropDownList2"] = DropDownList2.SelectedValue.ToString(); TextBox TextBox3 = new TextBox(); TextBox3.ID = "TextBox3"; TextBox3.Style["Position"] = "Absolute"; TextBox3.Style["Top"] = "400px"; TextBox3.Style["Left"] = "600px";
-
I am new to ASP.Net development in using C# In my webform there is one dropdown list called "DropDownList1". When i Select one of the items in this drpdownlist1, another dropdownlist is dynamically created called "DropdownList2". An I have to create more controls depends on the selection of "DropDownList2".But when i select DropdownList2 , its not working. ie: DropDownList_SelectedIndexChanged is not firing.Moreover the "DropDownList2" is get disappeared when i select the "DropDownList2". This is the code I have written.. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList drpDownListSender = (DropDownList)sender; string strDropDownList1ID = drpDownListSender.SelectedItem.Value; switch (strDropDownList1ID) { case "TRIN": Label SourceLabel = new Label(); SourceLabel.ID = "SourceLabel"; SourceLabel.Text = "SOURCE"; SourceLabel.Style["Position"] = "Absolute"; SourceLabel.Style["Top"] = "120px"; SourceLabel.Style["Left"] = "232px"; form1.Controls.Add(SourceLabel); DropDownList2 = new DropDownList(); DropDownList2.ID = "DropDownList2"; DropDownList2.Style["Position"] = "Absolute"; DropDownList2.Style["Top"] = "120px"; DropDownList2.Style["Left"] = "445px"; DropDownList2.AutoPostBack = true; DropDownList2.EnableViewState = true; DropDownList2.Visible = true; form1.Controls.Add(DropDownList2); DropDownList2.Items.Insert(0, "SELECT"); DropDownList2.Items.Insert(1, "CENTRAL STORE"); DropDownList2.SelectedIndexChanged += new System.EventHandler(DropDownList2_SelectedIndexChanged); break; case "TROUT": // Label4.Text = "Second Category Selected"; break; } protected void DropDownList2_SelectedIndexChanged(object sender,EventArgs e) { ViewState["DropDownList2"] = DropDownList2.SelectedValue.ToString(); TextBox TextBox3 = new TextBox(); TextBox3.ID = "TextBox3"; TextBox3.Style["Position"] = "Absolute"; TextBox3.Style["Top"] = "400px"; TextBox3.Style["Left"] = "600px";