displaying msg when no records are found

Hi experts,

if no records are shown, how do i display "no result"

<div>
    <p>Show all employees with the following title:
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Selected="True">Sales Representative</asp:ListItem>
            <asp:ListItem>Sales Manager</asp:ListItem>
            <asp:ListItem>Vice President, Sales</asp:ListItem>
        </asp:DropDownList></p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       
        <asp:SqlDataSource  id="SqlDataSource1"  runat="server"  ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees] WHERE ([LastName] LIKE '%' + @LastName + '%')"
  FilterExpression="Title='{0}' OR FirstName LIKE '%{1}%'">
  <FilterParameters>
    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
    <asp:ControlParameter Name="Name" ControlId="TextBox1" PropertyName="Text"/>
  </FilterParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="LastName" PropertyName="Text" Type="String" />
            </SelectParameters>
</asp:SqlDataSource>
       
       
       
            <p><asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView>
           </div>

thansk
SirReadAlotAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

fredmastroCommented:
If I was to do this, I wouldn't use the built in datasource, might want to create your own method that pulls the information, puts it into a dataset, if there are no rows then you could set the dropdown list to say "No Records Found".  You could use instead of the SqlDataSource, use the ObectDataSource instead.  
0
SirReadAlotAuthor Commented:
hi,

i am filling  a gridview control, if no data is returned i need to display results
0
fredmastroCommented:
You could do this...
Add this to your front-end page, above your gridview...

<asp:Label ID="DataMessageLabel" runat="server" /><br />

Then on your code behind you could do something like...

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If GridView1.Rows.Count = 0 Then
            DataMessageLabel.Text = "No Rows Found"
        Else
            DataMessageLabel.Text = ""
        End If

    End Sub
0
fredmastroCommented:
Ok yeah and don't put it in Page_Load like I have it.. put it in GridView1_DataBound.....,  I also had changed AutoEventWrireUp to true.

    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        If GridView1.Rows.Count = 0 Then
            '_mRowsFound = False
            DataMessageLabel.Text = "No Rows Found"
        Else
            '_mRowsFound = True
            DataMessageLabel.Text = ""
        End If
    End Sub



<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
 
    <p>Show all employees with the following title:
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Selected="True">Sales Representative</asp:ListItem>
            <asp:ListItem>Sales Manager</asp:ListItem>
            <asp:ListItem>Vice President, Sales</asp:ListItem>
        </asp:DropDownList></p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
        <asp:SqlDataSource  id="SqlDataSource1"  runat="server"  ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees] WHERE ([LastName] LIKE '%' + @LastName + '%')" 
  FilterExpression="Title='{0}' OR FirstName LIKE '%{1}%'">
  <FilterParameters>
    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
    <asp:ControlParameter Name="Name" ControlId="TextBox1" PropertyName="Text"/>
  </FilterParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="LastName" PropertyName="Text" Type="String" />
            </SelectParameters>
</asp:SqlDataSource>
      
            
            <p><asp:Label ID="DataMessageLabel" runat="server" /><br /><asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView>
     
    </form>
</body>
</html>
 
 
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        If GridView1.Rows.Count = 0 Then
            DataMessageLabel.Text = "No Rows Found"
        Else
            DataMessageLabel.Text = ""
        End If
    End Sub
End Class

Open in new window

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
fredmastroCommented:
You could also instead use the EmptyDataTemplate in the GridView.
Then you could setup a template that will show when no records are present.
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.