如何在Content Place持有者中循环控件

时间:2013-09-25 06:32:16

标签: c# asp.net

protected void btnbatch_Click(object sender, EventArgs e)
{       
    Button btnactual= sender as Button;
    ContentPlaceHolder myContent =
(ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
}

如何使用for-each在内容占位符中查找控件。我将代码放在Div tag中 但我没有得到。

任何人都可以帮帮我吗?

1 个答案:

答案 0 :(得分:6)

Protected void btnbatch_Click(object sender, EventArgs e)
{

    Button btnactual= sender as Button;
    ContentPlaceHolder myContent = 
   (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");

    foreach (Control ctrl in myContent.FindControl("divBatches").Controls)
    {
        if (ctrl.ID == btnactual.ID)
        {
           //blah blah
        }
     }
  }

试试这个......