动态添加的Checked Changed事件未触发 [英] Dynamically added Checked Changed Event is not Firing

查看:59
本文介绍了动态添加的Checked Changed事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经动态添加了列和复选框...但是遇到了一个问题,即未触发CheckedChanged事件.这是我的代码..


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


// binding datatable Dynamically..
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

推荐答案

因为控件是动态创建的,因此必须在创建过程中重新创建事件发生前的任何回发.检查以确保发生这种情况.

您可以在事件期间添加控件,例如RowCreated,然后在选定行时使用JavaScript显示/隐藏.
Because the controls are created dynamically they must be recreated during any postback before the events will fire. Check to make sure this is happening.

You could add the controls during an event, such as RowCreated, then use JavaScript to show/hide when the row is selected.


Haii ..

我已经通过在页面加载事件中重新创建动态控件解决了该问题..现在回退中未刷新复选框..谢谢大家...
Haii..

I have solved the Issue By recreating the Dynamic Controls In Page Load Event.. Now Checkboxes are Not Refreshed in Postback.. thank u All...


这篇关于动态添加的Checked Changed事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆