Welcome to Bilal Haidar [MVP, MCT] Official Blog Sign in | Join | Help

DataList Show/Hide Table Rows

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

Published Saturday, February 11, 2006 2:31 PM by BilalHaidar [MVP]

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required)