Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6221755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:11:21+00:00 2026-05-24T08:11:21+00:00

I have a gridview that is bound to an ObjectDataSource, which retrieves records from

  • 0

I have a gridview that is bound to an ObjectDataSource, which retrieves records from a database to display in the gridview. The procedure for returning the records takes in a search string and displays the relevant results. However when there are no results from the database, I get an empty gridview with the page numbers along the bottom, as if it returned all the records from the database, as shown in the pic below:

enter image description here

I have set both the EmptyDataText and EmptyDataTemplate properties, but they do not show when there are no results.

Anyone know what’s going on here?

Here’s the asp for the ObjectDataSource and GridView:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" SelectCountMethod="GetUsersCount"
        SelectMethod="GetUsers" SortParameterName="sortColumn" TypeName="WebsiteBuilder.Core.UUser"
        OnSelecting="ObjectDataSource1_Selecting">
        <SelectParameters>
            <asp:Parameter Name="searchExpression" Type="String" DefaultValue="" />
        </SelectParameters>
    </asp:ObjectDataSource>

<asp:GridView ID="grdUsers" runat="server" CssClass="grdUsers" AutoGenerateColumns="false"
        OnDataBound="grdUsers_DataBound" DataSourceID="ObjectDataSource1" AllowPaging="true"
        AllowSorting="true" OnRowCommand="grdUsers_RowCommand" PageSize="5" EmptyDataText="No Results">
        <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast"
            PageButtonCount="5" Position="Bottom" />
        <PagerStyle CssClass="pagination" HorizontalAlign="Center" VerticalAlign="Middle" />
        <EmptyDataTemplate>No Results</EmptyDataTemplate>`

Here is the code for the selecting event:

        protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        if (!String.IsNullOrEmpty(this.txtSearchBox.Text))
        {
            e.InputParameters["searchExpression"] = "%" + this.txtSearchBox.Text + "%";
        }
        else return;

    }

And the code for fetching the data:

            cmd.AddParameter("searchExpression", searchExpression);
            cmd.AddParameter("sortExpression", sortColumn);
            cmd.AddParameter("startRowIndex", startRowIndex);
            cmd.AddParameter("maximumRows", maximumRows);

            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            DataTable dt = ds.Tables[0];

            int i = dt.Rows.Count;

            return ds.Tables[0];

When I check i in debug the value is 0. My question is why the gridview is not showing the EmptyDataTemplate and why it is still showing multiple page numbers when there are no rows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:11:23+00:00Added an answer on May 24, 2026 at 8:11 am

    I would just bind the empty result set to the GridView, and then use the OnDataBound event to perform the appropriate logic, i.e. hide the GridView, display a “No Results” label, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to
In my website, I have a gridview which has datasource dynamically bound from database
I have a GridView control bound to an ObjectDataSource which returns a list of
I have a GridView that is bound to an ObjectDataSource that is calling a
I have a GridView that is bound to an ObjectDataSource, and I am handling
I have a GridView that is bound to a DataTable, which in turn uses
I have a GridView that is bound to a select statement from a table.
I have a GridView bound to an ICollection<UserAnswer> that needs to show two columns:
I have a GridView that I would like to bind to an ObjectDataSource. I
I have a gridview I bound a DataTable with that Gridview Its dynamic so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.