Feb 12 2006

DataList Show/Hide Table Rows

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 00:31

In the last few days, I was working on a Custom DotNetNuke Module, which is called ContactUs, which I will be using in one of the projects currently under my hands.

I wanted to list all entries of the ContactUs form that are stored in the database. So I decided to use the DataList, in which I place my own Table inside the ItemTemplate.

There are some fields in the ContactUs form that might be empty or null. So I didn't want to show the ROW inside the table for each NULL field in the database.

Here how I did it:

<asp:datalist id="dlstContactUs" runat="server" cellpadding="4" datakeyfield="itemId">
    <ItemTemplate>
        <table cellSpacing="0" cellPadding="2" border="0">
            <tr vAlign="top" runat="server" id="trCompany" Visible='<%# IsNull(DataBinder.Eval(Container.DataItem,"Company")) %>'>
               </tr>
        </table>
    </ItemTemplate>
</asp:datalist>

Watch the DarkGreen areas above.

In the code-behind, this is the IsNull method that I am using:

public bool IsNull(object item)
{
    if ((item.ToString() != null) && (item.ToString() != String.Empty))
    {
        return true;
    }
        return false;
}

Hope that helps,

Regards

Tags: ,

Comments are closed