Click here to Skip to main content
15,885,875 members

my dynamic ddl selectindexchanged is not firing

Shafik asked:

Open original thread
Hi All,

My dynamic control ddl selectindexchanged is not firing. below is my code.

public void LoadControlData(System.Web.UI.WebControls.Table t, bool IsPostBack, params object[] parameters)
        {
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();
            IReportData reportInputData = new FieldAuditActivityForDistrictsReportData();
            DataSet ds = reportInputData.GetReportInputData();

            if (IsPostBack == true)
            {
                DropDownList ddlTaxType = (DropDownList)t.FindControl("ddlRegionID");
                ddlTaxType.AppendDataBoundItems = true;
                ddlTaxType.Items.Insert(0, "");
                ddlTaxType.SelectedIndex = 0;
                ddlTaxType.DataSource = ds.Tables[0];
                ddlTaxType.DataTextField = "RegionName";
                ddlTaxType.DataValueField = "RegionID";
                _regionID =ddlTaxType.DataValueField;
                ddlTaxType.DataBind();

                //DropDownList ddlAuditors = (DropDownList)t.FindControl("ddlOfficeID");
                //ddlAuditors.AppendDataBoundItems = true;
                //ddlAuditors.Items.Insert(0, "");
                //ddlAuditors.SelectedIndex = 0;
                //ddlAuditors.DataSource = ds.Tables[1];
                //ddlAuditors.DataTextField = "OfficeName";
                //ddlAuditors.DataValueField = "OfficeID";
                //ddlAuditors.DataBind();
            }

            _tableHold = t;

            _lbuttoned = (LinkButton)t.FindControl("lbuttonEndDateID");
            _ddlRegion = (DropDownList)t.FindControl("ddlRegionID");
            Calendar cldred = (Calendar)t.FindControl("cldrEndDateID");
            _lbuttoned.Click += new EventHandler(lbuttoned_Click);   
            cldred.SelectionChanged += new EventHandler(cldred_SelectionChanged);
            cldred.VisibleMonthChanged += new MonthChangedEventHandler(cldred_VisibleMonthChanged);
            cldred.Visible = false;
            _ddlRegion.SelectedIndexChanged += new EventHandler(ddlRegion_SelectedIndexChanged);
            //_ddlRegion.SelectedIndexChanged += new EventHandler(ddlRegion_SelectedIndexChanged);
        }



public void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataRow dr = null;            
            IDataAccess da = DataAccessFactory.Create("ATS");
            List<idbdataparameter> pars = new List<idbdataparameter>();
            IDbDataParameter param1 = new SqlParameter(DataConstants.DataConstants.REGION_ID,_regionID);
            pars.Add(param1);

            SqlDataReader reader = (SqlDataReader)da.ExecuteReader(ProcedureConstants.FIELD_AUDIT_ACTIVITY_FOR_DISTRICTS_DISTRICTS_INPUT, ref pars, true);

            DataTable dt = new DataTable();

            DataColumn dc1 = new DataColumn("officeid");
            DataColumn dc2 = new DataColumn("officename");


            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);

            while (reader.Read())
            {
                dr = dt.NewRow();
                dr[dc1] = reader["officeid"];
                dr[dc2] = reader["officename"];
                dt.Rows.Add(dr);
            }

            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            
            //DropDownList ddlTaxType = (DropDownList)t.FindControl("ddlRegionID");
            //ddlTaxType.AppendDataBoundItems = true;
            //ddlTaxType.Items.Insert(0, "");
            //ddlTaxType.SelectedIndex = 0;
            //ddlTaxType.DataSource = ds.Tables[0];
            //ddlTaxType.DataTextField = "RegionName";
            //ddlTaxType.DataValueField = "RegionID";
            //_regionID = ddlTaxType.DataValueField;
            //ddlTaxType.DataBind();
        }

do you have any idea.

Thanks in advance

Shafik
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900