Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
Posted 8-Feb-13 5:26am
Shafik487
Edited 8-Feb-13 5:27am
v2
Comments
richcb at 8-Feb-13 11:28am
   
You will need to post your markup for the ddl as well. Use the "Improve question" widget to add that.
ryanb31 at 8-Feb-13 11:35am
   
Try setting AutoPostBack to true on your ddl.
Sandeep Mewara at 8-Feb-13 11:45am
   
1. is Autopostback set to true for ddlRegionID?
2. Why use/define a variable same as keyword and confuse? IsPostback is a defined page property, so use some other variable name in your method.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

set autopostback property to true while creating your dropdown
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Yes thanks guys.
 
_ddlRegion.AutoPostBack = true;
 
is the answer. Now it's working fine
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 403
1 OriginalGriff 354
2 George Jonsson 202
3 Shemeemsha RA 148
4 Animesh Datta 130
0 OriginalGriff 6,189
1 Sergey Alexandrovich Kryukov 5,666
2 CPallini 4,810
3 George Jonsson 3,429
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100