Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to hide an empty column of a repeater?

Status
Not open for further replies.

collegian

Programmer
Jul 1, 2010
64
US
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><asp:placeHolder id="repeaterPlaceholder" runat="server"><td> <b><font size="2px">Abstract: </font></b></td><td><%#Eval("Abstract")%> </td></asp:placeHolder></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.
 
Thanks for the reply.The issue is that that not all the values in the column are null,a few are null and a few are not,so I can't use display:none directly.

When I use a loop as I've done above it always takes the last value and hides or displays the column according to it.I need something dynamic which hides/displays column based on each and every value.
 
I figured out that I can use a function to show or hide values and it worked!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top