Here's my situtation. I have a Repeater bound to a List, which is rendering Table rows. I'm using <%# DataBinder.Eval(Container.DataItem, "SomeStringProperty")%> to display my data. The problem is that when the SomeStringProperty is null, string.Empty, or " " (some whitespace), the border for my TD is not getting rendered. Its as if its empty and quite ugly. I'm not sure how to handle this. Googling hasn't yielded the ans. Maybe someone here can tell me. Thanks..
views:
186answers:
1
+2
A:
I would replace the call to DataBinder.Eval with a Literal control and handle the Repeater's ItemDataBound event (OnItemDataBound). In the handler, check if the item is null and return a non-breaking space
if it is.
You could also wrap the Eval in a method call for the same effect:
<%# CheckNull(Eval("SomeStringProperty")) %>
in the code behind:
protected string CheckNull(object value)
{
return string.IsNullOrEmpty(value) ? "SEE BELOW" : value.ToString();
}
I can't get this to display correctly -- SEE BELOW should be replaced with
You may need to compare the value to System.DBNull.Value in addition to string.IsNullOrEmpty if it's coming from a database.
Jamie Ide
2009-06-17 22:26:35
I've tried your suggestion hooking the my Repeater's ItemDataBound event. My <TD>s are still empty even when I replace string.Empty/null with nbsp;. How/where should hook this function up?
Joel
2009-07-28 22:30:54
Found it. You need to hook the Repeater's ItemCreated. Here's what I got to work.protected void AdjustmentRepeater_ItemCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { var adj = (AdjustLineItem)e.Item.DataItem; adj.ParticipantSSN = CheckNull(adj.ParticipantSSN).ToString(); adj.ParticipantName = CheckNull(adj.ParticipantName).ToString(); } }
Joel
2009-07-29 02:16:06