Hello All,
I have a repeater control bound to a data source.The data source has some empty values within it.I want to hide the repeater column when the value from the datasource is null or empty.I searched on google and tried to use a placeholder control to do the same.However,I can't think of anyway to show or hide it.Any suggestions will be grately appreciated.
Here is my .aspx file:
<asp:Repeater ID="Repeater_NewsItems" runat="server"
onitemdatabound="Repeater_NewsItems_ItemDataBound">
<HeaderTemplate>
<ul id="ticker">
</HeaderTemplate>
<ItemTemplate>
<li>
<h3>News ID: <%#Eval("ItemID")%></h3>
<table>
<tr><td><b><font size="2px">Title:</font></b></td><td> <%#Eval("Title")%></td></tr>
<tr><td><b><font size="2px">Event Date: </font></b></td><td><%#Eval("EventDate").ToString()%></td></tr>
<tr><asplaceHolder id="repeaterPlaceholder" runat="server"><td> <b><font size="2px">Abstract: </font></b></td><td><%#Eval("Abstract")%> </td></asplaceHolder></tr>
<tr><td><b><font size="2px">More Information: </font></b></td><td><a href='<%#Eval("FullStoryLink")%>' target="_blank"><%#Eval("FullStoryLink")%></a></td></tr>
<tr><td><b><font size="2px">Location: </font></b></td><td><%#Eval("Location")%></td></tr>
</table>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
and the code behind:
protected void Repeater_NewsItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
PlaceHolder repeaterPlaceholder = (PlaceHolder)e.Item.FindControl("repeaterPlaceholder");
//This logic is incorrect.
DataSet ds = DBQuery.getNewsTicker();
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (String.IsNullOrEmpty(dr["Abstract"].ToString()))
{
repeaterPlaceholder.Visible = false;
}
else
repeaterPlaceholder.Visible = true;
}
}
}
Thanks.
I have a repeater control bound to a data source.The data source has some empty values within it.I want to hide the repeater column when the value from the datasource is null or empty.I searched on google and tried to use a placeholder control to do the same.However,I can't think of anyway to show or hide it.Any suggestions will be grately appreciated.
Here is my .aspx file:
<asp:Repeater ID="Repeater_NewsItems" runat="server"
onitemdatabound="Repeater_NewsItems_ItemDataBound">
<HeaderTemplate>
<ul id="ticker">
</HeaderTemplate>
<ItemTemplate>
<li>
<h3>News ID: <%#Eval("ItemID")%></h3>
<table>
<tr><td><b><font size="2px">Title:</font></b></td><td> <%#Eval("Title")%></td></tr>
<tr><td><b><font size="2px">Event Date: </font></b></td><td><%#Eval("EventDate").ToString()%></td></tr>
<tr><asplaceHolder id="repeaterPlaceholder" runat="server"><td> <b><font size="2px">Abstract: </font></b></td><td><%#Eval("Abstract")%> </td></asplaceHolder></tr>
<tr><td><b><font size="2px">More Information: </font></b></td><td><a href='<%#Eval("FullStoryLink")%>' target="_blank"><%#Eval("FullStoryLink")%></a></td></tr>
<tr><td><b><font size="2px">Location: </font></b></td><td><%#Eval("Location")%></td></tr>
</table>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
and the code behind:
protected void Repeater_NewsItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
PlaceHolder repeaterPlaceholder = (PlaceHolder)e.Item.FindControl("repeaterPlaceholder");
//This logic is incorrect.
DataSet ds = DBQuery.getNewsTicker();
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (String.IsNullOrEmpty(dr["Abstract"].ToString()))
{
repeaterPlaceholder.Visible = false;
}
else
repeaterPlaceholder.Visible = true;
}
}
}
Thanks.