1

我有一个用户控件,我可以在其中进行控制,其中Repeater有两个图像按钮。

我希望能够将图像按钮的可见性设置为 false。

我可以像这样将用户控件的其他控件的可见性设置为 false ...

this.Comment1.FindControl("btnAddNote").Visible = false;

...但我无法ItemTemplateRepeater.

我怎样才能做到这一点?

4

1 回答 1

1

当您处理中继器内的控件时,FindControl 方法无法访问项目模板中的控件。为此,您必须遍历中继器的每个项目并在 RepeaterItem 上使用 FindControl。

由于您的中继器在用户控件内,我建议您在用户控件上创建一个这样的方法,并从页面调用它。

//user control
public void HideNotes(){
   foreach (RepeaterItem ri in Repeater1.Items)
      ri.FindControl("btnAddNote").Visible = false;
}

//page
void btn_hide_Click(object sender, EventArgs e){
   this.Comment1.HideNotes();
}
于 2011-10-20T19:09:06.133 回答