• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3550
  • Last Modified:

DataList empty item template

I want to show a message when there's no data in my datalist. I found the following, but, I get an error on the bool. If you have another way to do this, great, but, I'd also like to try to do it this way as a learning experience.
     <asp:DataList id="DataList3" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            <asp:HyperLink ID="ID" runat="server" target="_parent" NavigateUrl='<%# "Employment_detail.aspx?"%>'
                Text='<%# Bind("WJTTL") %>'/>
       </ItemTemplate>
        <FooterTemplate>
            <asp:Label ID="lblEmpty"
                Text="Nothing here." runat="server" Visible="true">
                        %>Visible='<%#bool.Parse((SqlDataSource1.Items.Count==0).ToString())%>'>              </asp:Label>
        </FooterTemplate>
    </asp:DataList>

thanks for looking and your comments
0
avoorheis
Asked:
avoorheis
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
I don't think there is a way to do it declaratively because the SqlDataSource doesn't return details of its records. You will probably have to handle the Selected event of the SqlDataSource and use the AffectedRows property to determine the number of records and then toggle the labels visibility through code.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Correction, there is a way to do it with a bit of fiddling. You still need to handle the Selected event of the SqlDataSource, but you can then expose that as a property of your page and bind to it:

        // code-behind stuff
        protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            hasRecords = e.AffectedRows > 0;
        }

        public bool HasRecords
        {
            get { return hasRecords; }
        }

        bool hasRecords = true;


   // markup
  <FooterTemplate>
      <asp:Label ID="EmptyLabel" runat="server" Text="Nothing Here" Visible='<%# !this.HasRecords %>' />
  </FooterTemplate>  
0
 
avoorheisAuthor Commented:
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now