Search code examples
c#asp.netgridviewcustom-paging

Custom paging in grid view control


I want custom pagination in my gridview control. The first option is to fetch only required row from the data base. But what I want is I am fetching all rows from the database and storing them into datatable. Now is there any option that I can bind only some of the rows of datatable to gridview based on page size and page index so that I no need to connect to database every time on page change event?


Solution

  • You have to handle the Gridview PageIndexChanging event and setup a New page index.

    like...

    protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       gridView.PageIndex = e.NewPageIndex;
       gridView.DataSource = (DataTable)Session["DataTable"];
       gridView.DataBind();
    }