Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PagedDatasource for gridview paging

I am using PagedDataSource for gridview's custom paging. Here is the code:

PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);
dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;

dataSource.VirtualCount = virtualRowCount;
dataSource.DataSource = dataset.Tables[0].DefaultView;


gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.DataBind();

I am returning the "totalrows" from my Stored procedure (which is set in virtualRowCount) and actual rows in tables[0] of dataset. I am getting the results however my pager is gone. The pager is no longer shown. How can I tell the gridview to pick up value from PagedDataSource?

Working with ASP.Net 4

like image 981
Jaggu Avatar asked Aug 22 '11 08:08

Jaggu


2 Answers

ASP.NET 2.0+ Version

This post here http://www.codewrecks.com/blog/index.php/2008/02/09/aspnet-20-gridview-custom-sorting-with-pageddatasource/ extends the standard GridView and provides plumbing code to achieve PagedDataSource integration.

ASP.NET 4.5 Version

Set the AllowPaging and AllowCustomPaging attribute on the GridView as well as the Paged data source property?

PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);
dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;

dataSource.VirtualCount = virtualRowCount;
dataSource.DataSource = dataset.Tables[0].DefaultView;

gvTaxPayerLoginDetail.AllowPaging = true; // See this line here
gvTaxPayerLoginDetail.AllowCustomPaging = true; // and this line here
gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.DataBind();

Additionally this post may also be of help http://www.byteblocks.com/post/2012/03/20/Use-Custom-Paging-in-Grid-View.aspx

like image 153
Luke Baughan Avatar answered Oct 20 '22 12:10

Luke Baughan


PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);

dataSource.DataSource = dataset.Tables[0].DefaultView;

dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;
dataSource.VirtualCount = virtualRowCount;
dataSource.CurrentPageIndex  =0;

gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.AllowPaging=True;
gvTaxPayerLoginDetail.DataBind();
like image 37
Anant Dabhi Avatar answered Oct 20 '22 14:10

Anant Dabhi