ASP.NET / C#: DropDownList SelectedIndexChanged event not firing?

You're not assigning an event handler in your RecreateDropDownLists() method :).

Up vote 4 down vote favorite 1 share g+ share fb share tw.

My selectedindexchanged event is not firing when I select values in my dropdown lists. These dropdown lists are implemented dynamically in the following code. I have tried changing autopostback and enableviewstate settings to no avail.

I am using a static panel. Does anyone see how I can cause the selectedindexchanged event to fire? Using System; using System.

Collections; using System.Collections. Generic; using System. Data; using System.Data.

SqlClient; using System. Diagnostics; using System. Web; using System.Web.

UI; using System.Web.UI. WebControls; using ADONET_namespace; namespace AddFileToSQL { public partial class DataMatch : _Default { protected System.Web.UI.WebControls. PlaceHolder phTextBoxes; protected System.Web.UI.WebControls.

PlaceHolder phDropDownLists; protected System.Web.UI.WebControls. Button btnAnotherRequest; protected System.Web.UI.WebControls. Panel pnlCreateData; protected System.Web.UI.WebControls.

Literal lTextData; protected System.Web.UI.WebControls. Panel pnlDisplayData; //Panel pnlDropDownList; protected static string inputfile2; static string headers = null; static string data = null; static string data2 = null; static DataTable myInputFile = new DataTable("MyInputFile"); static string myUserSelections; // a Property that manages a counter stored in ViewState protected int NumberOfControls { get { return (int)ViewState"NumControls"; } set { ViewState"NumControls" = value; } } public void EditRecord(object recordID) { SelectedRecordID = recordID; // Load record from database and show in control } protected object SelectedRecordID { get { return ViewState"SelectedRecordID"; } set { ViewState"SelectedRecordID" = value; } } // Page Load private void Page_Load(object sender, System. EventArgs e) { if (!Page.

IsPostBack) { this. NumberOfControls = 0; } } // Add DropDownList Control to Placeholder private void CreateDropDownLists() { for (int counter = 0; counter ")); pnlDisplayData. Visible = true; // pnlDropDownList.

FindControl(ddl. ID); dr.Close(); } } protected void SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; string ID = ddl. ID; } // Add TextBoxes Control to Placeholder private void RecreateDropDownLists() { for (int counter = 0; counter ")); } } // Create TextBoxes and DropDownList data here on postback.

Protected override void CreateChildControls() { // create the child controls if the server control does not contains child controls this. EnsureChildControls(); // Creates a new ControlCollection. This.

CreateControlCollection(); // Here we are recreating controls to persist the ViewState on every post back if (Page. IsPostBack) { RecreateDropDownLists(); RecreateLabels(); } // Create these conrols when asp.net page is created else { PopulateFileInputTable(); CreateDropDownLists(); CreateLabels(); } // Prevent child controls from being created again. This.

ChildControlsCreated = true; } // Read all the data from TextBoxes and DropDownLists protected void btnSubmit_Click(object sender, System. EventArgs e) { int cnt = FindOccurence("DropDownListID"); EditRecord("DropDownListID" + Convert. ToString(cnt + 1)); AppendRecords(); pnlDisplayData.

Visible = false; } private int FindOccurence(string substr) { string reqstr = Request.Form.ToString(); return ((reqstr. Length - reqstr. Replace(substr, "").

Length) / substr. Length); } } } c# asp.net dropdownlist selectedindexchanged link|improve this question asked Jul 25 '09 at 1:06salvationishere7201831 63% accept rate.

Yes, this did it! Thanks! – salvationishere Jul 25 '09 at 2:39.

You don't seem to be wiring up to the DropDownList's SelectedIndexChanged event if it's postback. Given both the recreate and the create seem functionally identical, why not merge those? Encapsulate what varies.

Good point--I'll follow this advice. – salvationishere Jul 25 '09 at 2:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions