Main Logo
homelink tutorialslink softwarelink comicslink aboutlink contactlink

Tutorial: How to Handle NULL Database Values in an ASP.NET Repeater Control


Example ASP.NET Markup
<asp:Repeater ID="ValueRepeater" runat="server">
    <ItemTemplate>
        <asp:Label ID="ValueLabel" runat="server" Text='<%# ValueCheck(Container.DataItem, "ValueName") %>'></asp:Label>
        <br />
    </ItemTemplate>
</asp:Repeater>
    

Code Behind
protected string ValueCheck(object o, string s)
{
    //if database value is NULL, handle it
    if (Convert.IsDBNull(DataBinder.Eval(o, s)))
    {
        s = "Null Value!";
    }
    else 
    {
       s = DataBinder.Eval(o, s).ToString();
    } 

    return s;
}
    

Last Updated: June 30, 2011