Here i have binded repeater with Dummy table. I have set marks3 value as 0 by default and On ItemDataBoundEvent, if marks3 value is zero then it will hide Header and also the label and if any row containing any other value for marks3 then it will show the Marks3 Header and value also.
<table>
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Marks1
</th>
<th>
Marks2
</th>
<th id="marks" runat="server">
Matks3
</th>
</tr>
<asp:Repeater ID="rptDemo" runat="server" OnItemDataBound="ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID")%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name")%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblMarks1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Marks1")%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblMarks2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Marks2")%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblMarks3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Marks3")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5]{new DataColumn("ID",typeof(int)),
new DataColumn("Name",typeof(string)),
new DataColumn("Marks1",typeof(int)),
new DataColumn("Marks2",typeof(int)),
new DataColumn("Marks3",typeof(int))});
dt.Rows.Add(1, "John", 85, 75, 0);
dt.Rows.Add(2, "Jack", 87, 74, 0);
dt.Rows.Add(3, "Micheal", 88, 71, 20);
rptDemo.DataSource = dt;
rptDemo.DataBind();
}
}
OnItemDataBound
protected void ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label activeLabel = (Label)e.Item.FindControl("lblMarks3");
string s = activeLabel.Text;
if (s == "0")
{
activeLabel.Visible = false;
marks.Visible = false;
}
else
{
activeLabel.Visible = true;
marks.Visible = true;
}
}
}