Hi Guys,
I have a repeater that should show a bound field value only if it exists. Having read this post I decided to do it by using a literal within my repeater and using the OnItemDatabound trigger to populate my literal but my literal doesn't seem to be accessible from the c# code behind and I don't understand why!
Heres the aspx page
<asp:Repeater runat="server" ID="rpt_villaresults" OnItemDataBound="checkForChildren">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
//.................MORE CODE HERE......................
<div class="sleeps"><h4>To Sleep</h4><h5><%#Eval("sleeps")%> <asp:Literal ID="sleepsChildrenLit" runat="server" /> </h5></div>
//.............MORE CODE HERE........................
And the code behind
public void checkForChildren(object sender, RepeaterItemEventArgs e)
{
Literal childLit = e.Item.FindControl("sleepsChildrenLit") as Literal;
//this is null at runtime
String str = e.Item.DataItem.ToString();
if (e.Item.DataItem != null)
{
if (Regex.IsMatch(str, "[^0-9]"))
{
if (Convert.ToInt32(str) > 0)
{
childLit.Text = " + " + str;
}
}
}
}