在后台CS文件里面,隐藏和显示Repeater里面控件

时间:2022-08-28 18:28:29
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Panel ID="p1" runat="server">
<a href='a.aspx?Id=<%# Eval("id") %>'>编辑</a>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item
// used to include <ItemTemplate> and <AlternatingItemTemplate>
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Panel panel1 = (Panel)e.Item.FindControl("p1");
if (flag == true)
panel1.Visible = true;
else
panel1.Visible = false;
}
}

other methods:


for(int i=0;i<Repeater1.Items.Count;i++)
{
Panel pl= Repeater1.Items[i].FindControl("p1") as Panel;
if(....)
{
pl.Visible=false;
}
}


foreach(RepeaterItem item in Repeater1.Items)
{
Panel pl= (Panel)item.FindControl("p1");
// 你的代码
}