Dynamically added Checked Changed Event is not Firing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anish222
    New Member
    • Mar 2012
    • 2

    Dynamically added Checked Changed Event is not Firing

    hi seniors.. I have added columns and checkboxes Dynamically... But met with a problem that the CheckedChanged Event is not fired.. here is my Code..

    Code:
    protected void ddlRole_SelectedIndexChanged(object sender, EventArgs e)
    {
    
    
            for (int i = 0; i < DtOperation.Rows.Count; i++)
            {
                Dt.Columns.Add(DtOperation.Rows[i][0].ToString());
            }
            dgrDynamic.DataSource = Dt;
            dgrDynamic.DataBind();   
    .
    .
            //addind check boxes dynamically.
    
            tcCheckCell = new TableCell();
            var checkBox = new CheckBox();
    
           // ActivityID|OperationID is stored to work it at the time of Save in CheckedChanged.
    
           checkBox.ID = DtOperation.Rows[i][0] + "|" + DtOperation.Rows[i][2];
           checkBox.AutoPostBack = true;
           checkBox.Checked = true;
           checkBox.CheckedChanged +=new EventHandler(checkBox_CheckedChanged);
    
            tcCheckCell.Controls.Add(checkBox);
                                            dgrDynamic.Rows[j].Cells.RemoveAt(GetColumnIndexByName((int)DtOperation.Rows[i][2]));
                        dgrDynamic.Rows[j].Cells.AddAt(GetColumnIndexByName((int)DtOperation.Rows[i][2]), tcCheckCell);
                        //(int)DtOperation.Rows[i][2]+2   
    }
    
    
    void checkBox_CheckedChanged(object sender, EventArgs e)
    {
    
    ...Code;
    }
    am a fresher in this field and can you pls help me to Over come the misery.. Thank you all
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You need to re-load the dynamically created controls in your PageInit event or else the events for these controls will not be fired.

    See how to use dynamic controls in asp.net for more information.

    -Frinny
    Last edited by Frinavale; Mar 8 '12, 02:46 PM.

    Comment

    • anish222
      New Member
      • Mar 2012
      • 2

      #3
      Thank U senior.. Bt since am Jst Beginner In this profession.. can u pls jst be little more Specific..

      Comment

      Working...