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
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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With