[RESOLVED]DataList Empty designator in Footer Template

I’m trying to create a label that becomes visible if my datalist is empty.  Unfortunately, this code never shows the label even when the data is empty and I don’t understand why….

 

All I see is "nothing".  The NoResultsLbl Label is never displayed in the footer. 

 

<asp:DataList ID="ProdSearchDL" runat="server" DataKeyField="myID" DataSourceID="ProdDataSource1"
            RepeatColumns="3" RepeatDirection="Horizontal">
            <ItemTemplate>
                <table class="Prod-Table">
                    <tr>
                        <td style="width: 100px">
                            <asp:HyperLink ID="ImageHyperLink" runat="server" AlternateText='<%# Eval("ShortName") %>'
                                ImageUrl='<%# ProdImgURL(Eval("DetailID")) %>' NavigateUrl='<%# GetProductURL(Eval("DetailID")) %>'
                                ToolTip='<%# Eval("ShortName") %>'>HyperLink</asp:HyperLink></td>
                    </tr>
                    <tr>
                        <td style="width: 100px">
                            <asp:HyperLink ID="ProdHyperLink" runat="server" CssClass="Nav-Menu-Main" NavigateUrl='<%# GetProductURL(Eval("DetailID")) %>'
                                Text='<%# Eval("ShortName") %>' ToolTip='<%# Eval("FullName") %>'></asp:HyperLink></td>
                    </tr>
                </table>
            </ItemTemplate>
            <FooterTemplate>
            <asp:Label ID="NoResultsLbl" runat="server" CssClass="Errors"
            Text="Sorry, No Results Available for that Search !" Visible='<%# Boolean.Parse((ProdSearchDL.Items.Count = 0).ToString())%>'></asp:Label>
            </FooterTemplate>
        </asp:DataList>

Most likely your expression is not evaluating correctly.  This is why you should not mix markup with code, because it is not easily debugable.  I would simple use the code-behind to set the visible property based on your value.

A better idea is to use a MultiView control.  Have one view that shows the results when you have them, and another view to display your message.  Then in the codebehind, when you bind the data, set the appropriate view visible (SetActiveView(view) method).

Got that bit of a code from another post as "answer" in this forum.

Leave a Reply