Click here to Skip to main content
15,065,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,

I am searching data with name and id the filtered data is binding to gridview.

I am using Gridview1_PageIndexChanging Event for paging.I am storing filtered data
into viewstate and binding viewstate data in the page index changing.

Datatable has nearly 6000+ recods.

Performance of loading data into gridview and on page index changing is very slow.

how to improve loading performance of gridview?

What I have tried:

grdMembers.PageIndex = e.NewPageIndex;

if (ViewState["grdview"] != null)

DataTable Dt = (DataTable)ViewState["grdview"];
grdMembers.DataSource = Dt;
Updated 4-Oct-17 21:06pm
Mehdi Gholam 2-Jul-16 12:58pm
Show less data and use paging.
ZurdoDev 2-Jul-16 22:49pm
Paging and less data are really the only ways to speed this up. Test your sql in Sql Management Studio and make sure you get that running as fast as possible. \

How big are your pages?
jayveebishie 3-Jul-16 13:31pm
Are you using stored procedure to fetch the data? If yes, use paging on your store procedure
The Praveen Singh 4-Aug-16 6:32am
Use Server side paging, also optimize your query if possible.
Richard Deeming 5-Oct-17 13:12pm
Don't store a 6000-record DataTable in ViewState. If you do, every response will contain multiple megabytes of encoded ViewState data which has to be downloaded, and every request will have to send all of that data back up to the server.

This should help you.
CHill60 5-Oct-17 3:17am
There is nothing here!
GKP1992 5-Oct-17 4:26am
There are 3 quite helpful links in the solution to the question asked in the link. Question are somewhat similar.
CHill60 5-Oct-17 10:40am
The link on "This" was not showing up on the device I was using when I posted the comment. My apologies
GKP1992 5-Oct-17 23:52pm
No problem. :-)
If you are using stored procedure to fetch data from database, you should use pagination i.e. send the page number and and page size and then select those specific records and return when page index of gridview is changed (google will give lot of examples). Also, you should create required indexes to make your query perform better. For example, if you do not have indexes on the columns you are using in your query, then create index(es) as required. Name column should also have a non-clustered index on it.

Another alternate could be to display recent records e.g. if you have a timestamp column in your table sort in descending order by this column and return top 1000 records.
Use Paging
<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)

    // Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;

    // Retrieve the PageDropDownList DropDownList from the bottom pager row.
    DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");

    // Set the PageIndex property to display that page selected by the user.
    CustomersGridView.PageIndex = pageList.SelectedIndex;


  protected void CustomersGridView_DataBound(Object sender, EventArgs e)

    // Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;

    // Retrieve the DropDownList and Label controls from the row.
    DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
    Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");

    if(pageList != null)

      // Create the values for the DropDownList control based on 
      // the  total number of pages required to display the data
      // source.
      for(int i=0; i<CustomersGridView.PageCount; i++)

        // Create a ListItem object to represent a page.
        int pageNumber = i + 1;
        ListItem item = new ListItem(pageNumber.ToString());         

        // If the ListItem object matches the currently selected
        // page, flag the ListItem object as being selected. Because
        // the DropDownList control is recreated each time the pager
        // row gets created, this will persist the selected item in
        // the DropDownList control.   
          item.Selected = true;

        // Add the ListItem object to the Items collection of the 
        // DropDownList.



    if(pageLabel != null)

      // Calculate the current page number.
      int currentPage = CustomersGridView.PageIndex + 1;     

      // Update the Label control with the current page information.
      pageLabel.Text = "Page " + currentPage.ToString() +
        " of " + CustomersGridView.PageCount.ToString();




<html xmlns="" >
  <head runat="server">
    <title>GridView PagerTemplate Example</title>
    <form id="form1" runat="server">

      <h3>GridView PagerTemplate Example</h3>

      <asp:gridview id="CustomersGridView" 

        <pagerstyle forecolor="Blue"


          <table width="100%">                    
              <td style="width:70%">

                <asp:label id="MessageLabel"
                  text="Select a page:" 
                <asp:dropdownlist id="PageDropDownList"


              <td style="width:70%; text-align:right">

                <asp:label id="CurrentPageLabel"





      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900