ASP.NET VB DataList Control - Show message when record set is empty

I have a simple ASP.NET VB page that pulls records from a database and displays the results nicely on the page. What I would like to do however is to have a message "No Records Found" displayed if there are no records. If there are records, I would like the DataList to be displayed.

This is very easy in Classic ASP, but I cant figure it in MS. .NET.
guildernetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guildernetAuthor Commented:

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" %>

<script runat="server">

    Protected Sub ListView1_SelectedIndexChanged(sender As Object, e As System.EventArgs)

    End Sub
    
    Protected Sub TennesseeListView_SelectedIndexChanged(sender As Object, e As System.EventArgs)

    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs)

    End Sub

    Protected Sub RsNisky_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
   
        
        If DataList4.Items.Count = 0 Then
            'There are no records
            DataList4.Visible = False
            lblnisky.Visible = True
        Else
            DataList4.Visible = True
            lblnisky.Visible = False
        End If
        
    End Sub

    Protected Sub DataList4_SelectedIndexChanged(sender As Object, e As System.EventArgs)

       
        
    End Sub

    Protected Sub DataList3_SelectedIndexChanged(sender As Object, e As System.EventArgs)

    End Sub

    Protected Sub RsRotterdam_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
        
        
        
    End Sub
</script>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
   

   <table cellspacing="0" cellpadding="0" border="0" align="center" width="750">
<tr>
	<td>
	 <p align="center" class="style1">Employee Emergency Information Center</p>

     <div class="SubTitleTxt">
       <p class="Topboxtxt">Welcome to the SI Group Employee Emergency Information Center. Currently this site covers our New York, Texas and Tenessee Operations.</p>
    
    
     <%--  *************** Freeport Texas Events ********************** --%>
       
       <asp:SqlDataSource 
             ID="TexasAlerts" runat="server" 
             ConnectionString="<%$ ConnectionStrings:TexasAlerts %>" 
             
             
             SelectCommand="SELECT [ArticleTitle], [DatePosted], [ArticleID], [EventTypeTxt], [EventTypeImage] FROM [sqryEEICAdminView] WHERE ([EEICLocationID] = @EEICLocationID)">
         <SelectParameters>
             <asp:Parameter DefaultValue="4" Name="EEICLocationID" Type="Int32" />
         </SelectParameters>
         </asp:SqlDataSource>
        </div>
       
       
       <%--  *************** Freeport Texas DataList ********************** --%>

          <br />
        
        <div align="center">
        
        <asp:DataList ID="DataList1" runat="server" CellPadding="4" 
            DataKeyField="ArticleID" DataSourceID="TexasAlerts" ForeColor="#333333" 
            ShowFooter="False">
            <AlternatingItemStyle BackColor="White" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#184cb1" Font-Bold="True" Font-Italic="False" 
                Font-Names="Verdana" Font-Overline="False" Font-Size="Small" 
                Font-Strikeout="False" Font-Underline="False" ForeColor="White" 
                HorizontalAlign="Center" VerticalAlign="Middle" />
            <ItemStyle BackColor="#E7E9E4" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />


               <HeaderTemplate>
                    Alerts for Freeport Texas 
               </HeaderTemplate>
             

            <ItemTemplate>
               

               <img alt="Image" align="middle" src="<%# Eval("EventTypeImage") %>">&nbsp;&nbsp;

               <span class="style4">** <%# Eval("EventTypeTxt") %> **</span> &nbsp;

               <span class="style3">&nbsp;<a href="event.aspx?Article=<%# Eval("ArticleID") %>"><%# Eval("ArticleTitle") %></a></span>&nbsp;&nbsp;<span class="style3"><b>Posted</b> <%# Eval("DatePosted") %></span>


            </ItemTemplate>
            <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                ForeColor="#333333" HorizontalAlign="Left" VerticalAlign="Middle" />
        </asp:DataList>

        <br />

        </div> 

      
        <!-- **************** END TEXAS EVENTS ************************** -->





      <!-- **************** TENNESSEE EVENTS ************************** -->
       

       <div align="center">

	    <asp:SqlDataSource ID="RsTennessee" runat="server" 
            ConnectionString="<%$ ConnectionStrings:TexasAlerts %>" 
            
            
            SelectCommand="SELECT [ArticleTitle], [DatePosted], [ArticleID], [EventTypeTxt], [EventTypeImage] FROM [sqryEEICAdminView] WHERE ([EEICLocationID] = @EEICLocationID)">
            <SelectParameters>
                <asp:Parameter DefaultValue="5" Name="EEICLocationID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

        <br />
        <asp:DataList ID="DataList2" runat="server" CellPadding="4" 
            DataKeyField="ArticleID" DataSourceID="RsTennessee" ForeColor="#333333" 
            ShowFooter="False">
            <AlternatingItemStyle BackColor="White" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />
            <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                VerticalAlign="Middle" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#184CB1" Font-Bold="True" Font-Italic="False" 
                Font-Names="Verdana" Font-Overline="False" Font-Size="Small" 
                Font-Strikeout="False" Font-Underline="False" ForeColor="White" 
                HorizontalAlign="Center" VerticalAlign="Middle" />
            <ItemStyle BackColor="#E7E9E4" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />


                <HeaderTemplate>
                    Alerts for Newport Tennessee 
               </HeaderTemplate>


            <ItemTemplate>
               

               <img alt="Image" align="middle" src="<%# Eval("EventTypeImage") %>">&nbsp;&nbsp;

               <span class="style4">** <%# Eval("EventTypeTxt") %> **</span> &nbsp;

               <span class="style3">&nbsp;<a href="event.aspx?Article=<%# Eval("ArticleID") %>"><%# Eval("ArticleTitle") %></a></span>&nbsp;&nbsp;<span class="style3"><b>Posted</b><%# Eval("DatePosted") %></span>


            </ItemTemplate>


            <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                ForeColor="#333333" HorizontalAlign="Left" VerticalAlign="Middle" />
        </asp:DataList>

        <br />


           <!-- **************** ROTTERDAM EVENTS ************************** -->

           <asp:SqlDataSource ID="RsRotterdam" runat="server" 
               ConnectionString="<%$ ConnectionStrings:TexasAlerts %>" 
               
               SelectCommand="SELECT [ArticleTitle], [DatePosted], [ArticleID], [EventTypeImage], [EventTypeTxt] FROM [sqryEEICAdminView] WHERE ([EEICLocationID] = @EEICLocationID)" 
               onselecting="RsRotterdam_Selecting">
               <SelectParameters>
                   <asp:Parameter DefaultValue="3" Name="EEICLocationID" Type="Int32" />
               </SelectParameters>
           </asp:SqlDataSource>
           <br />
        <asp:DataList ID="DataList3" runat="server" CellPadding="4" 
            DataKeyField="ArticleID" DataSourceID="RsRotterdam" ForeColor="#333333" 
            ShowFooter="False" onselectedindexchanged="DataList3_SelectedIndexChanged">
            <AlternatingItemStyle BackColor="White" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />
            <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                VerticalAlign="Middle" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#184CB1" Font-Bold="True" Font-Italic="False" 
                Font-Names="Verdana" Font-Overline="False" Font-Size="Small" 
                Font-Strikeout="False" Font-Underline="False" ForeColor="White" 
                HorizontalAlign="Center" VerticalAlign="Middle" />
            <ItemStyle BackColor="#E7E9E4" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />


                <HeaderTemplate>
                    Alerts for Rotterdam Junction 
               </HeaderTemplate>


            <ItemTemplate>
               

               <img alt="Image" align="middle" src="<%# Eval("EventTypeImage") %>">&nbsp;&nbsp;

               <span class="style4">** <%# Eval("EventTypeTxt") %> **</span> &nbsp;

               <span class="style3">&nbsp;<a href="event.aspx?Article=<%# Eval("ArticleID") %>"><%# Eval("ArticleTitle") %></a></span>&nbsp;&nbsp;<span class="style3"><b>Posted</b> <%# Eval("DatePosted") %></span>


            </ItemTemplate>


            <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                ForeColor="#333333" HorizontalAlign="Left" VerticalAlign="Middle" />
        </asp:DataList>

           <br />

           <!-- **************** NISKAYUNA EVENTS ************************** -->

           <asp:SqlDataSource ID="RsNisky" runat="server" 
               ConnectionString="<%$ ConnectionStrings:TexasAlerts %>" 
               
               SelectCommand="SELECT [ArticleTitle], [DatePosted], [ArticleID], [EventTypeTxt], [EventTypeImage] FROM [sqryEEICAdminView] WHERE ([EEICLocationID] = @EEICLocationID)" 
               onselecting="RsNisky_Selecting">
               <SelectParameters>
                   <asp:Parameter DefaultValue="2" Name="EEICLocationID" Type="Int32" />
               </SelectParameters>
           </asp:SqlDataSource>
           <br />

         
        <asp:DataList ID="DataList4" runat="server" CellPadding="4" 
            DataKeyField="ArticleID" DataSourceID="RsNisky" ForeColor="#333333" 
            ShowFooter="False" onselectedindexchanged="DataList4_SelectedIndexChanged">
            <AlternatingItemStyle BackColor="White" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />
            <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                VerticalAlign="Middle" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#184CB1" Font-Bold="True" Font-Italic="False" 
                Font-Names="Verdana" Font-Overline="False" Font-Size="Small" 
                Font-Strikeout="False" Font-Underline="False" ForeColor="White" 
                HorizontalAlign="Center" VerticalAlign="Middle" />
            <ItemStyle BackColor="#E7E9E4" Font-Bold="False" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                HorizontalAlign="Left" VerticalAlign="Middle" />


                                      
                


                <HeaderTemplate>
                           Alerts for Niskayuna New York 
               </HeaderTemplate>


            <ItemTemplate>
               

               <img alt="Image" align="middle" src="<%# Eval("EventTypeImage") %>">&nbsp;&nbsp;

               <span class="style4">** <%# Eval("EventTypeTxt") %> **</span> &nbsp;

               <span class="style3">&nbsp;<a href="event.aspx?Article=<%# Eval("ArticleID") %>"><%# Eval("ArticleTitle") %></a></span>&nbsp;&nbsp;<span class="style3"><b>Posted</b> <%# Eval("DatePosted") %></span>


            </ItemTemplate>


            <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" Font-Italic="False" 
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                ForeColor="#333333" HorizontalAlign="Left" VerticalAlign="Middle" />
        </asp:DataList>

          
           <asp:Label ID="lblnisky" runat="server" 
               Text="** Currently there are no Alerts for Niskayuna, New York **" 
               Visible="False" CssClass="NoAlertTxt"></asp:Label>

        </div>
        <br />

        <!-- **************** END NISKAYUNA EVENTS ************************** -->


       <br /><br />

       	</td>
</tr>
</table>

</asp:Content>

Open in new window

0
käµfm³d 👽Commented:
What if you did something like:

Markup
<asp:DataList ID="DataList1" runat="server" CellPadding="4" 
              DataKeyField="ArticleID" DataSourceID="TexasAlerts" ForeColor="#333333" 
              ShowFooter="False">

...

    <FooterTemplate>
        No Data!
    </FooterTemplate>
</asp:DataList>

Open in new window


Code-Behind
...

Protected Sub RsNisky_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)

    If DataList4.Items.Count = 0 Then
        'There are no records
        DataList4.Visible = False
        lblnisky.Visible = True
        Me.DataList1.ShowFooter = True    ' Added
    Else
        DataList4.Visible = True
        lblnisky.Visible = False
    End If

End Sub

...

Open in new window

0
guildernetAuthor Commented:
No, no such luck i'm afraid.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

käµfm³d 👽Commented:
Have you tried using the Selected event rather than the Selectng event? Selecting occurs before data is retrieved; Selected occurs after.
0
guildernetAuthor Commented:
The solution actually ends up being the following.

Create a SQLData Source that connects to the table, or view that contains the data that you need.

Then, use the ListView Server control to return the data to the page. Once you have the correct data showing up on the page, I hand tweaked it to display in a table structure that I wanted. It works great.

In ListView Server control there is an option for what to display if there are no records to return. I put my custom CSS and Message in between those tags and it works like a charm.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guildernetAuthor Commented:
Ended up finding the answer though google.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.