How do I hide a particular column in Asp Repeater ? I want to hide POwner in this case !
<ItemTemplate>
<tr>
<td>
<%#Eval("Priority") %>
</td>
<td>
<%#Eval("ProjectName") %>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("POwner") %>'></asp:Label>
</tr>
</ItemTemplate>
Adding this in code behind gives an error :s
public void Repeater1_ItemDatabound(Object Sender, RepeaterItemEventArgs e)
{
Repeater a =(Repeater)e.Item.FindControl("Label1");
a.Visible = false;
}
Label1
is a Label
control and not Repeater
, that's why you're getting an error
You also need to add an if
condition so you only get the Label1
for items and not for header or footer.
Try with this
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Label label = (Label)e.Item.FindControl("Label1");
label.Visible = false;
}