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

<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");
// 你的代码
}

posted @ 2013-06-19 11:40  yuloe2012  阅读(1657)  评论(0编辑  收藏  举报