Repeater – Convert DbNull to Whitespace

In HTML,

<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table cellpadding=0 cellspacing=0 border=1>
<tr>
<td>Product Name</td>
<td>Unit Price</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "ProductName") %></td>
<td><%# formatWhiteSpace(DataBinder.Eval(Container.DataItem, "UnitPrice")) %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

In ASP.NET (VB),

''Change [ null,0 ] to ""
Protected Function formatWhiteSpace(ByVal argVal) As String
If argVal Is DBNull.Value Then
Return " "
ElseIf argVal = 0 Then
Return " "
Else
Return argVal
End If
End Function

One thought on “Repeater – Convert DbNull to Whitespace

Leave a Reply

Your email address will not be published. Required fields are marked *