PagedDatasource for gridview paging
Asked Answered
L

2

6

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

Lemuroid answered 22/8, 2011 at 8:14 Comment(1)
please can you accept an answer on this as I don't think you're gonna see much movementon it.Bugger
B
3

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

Bugger answered 13/8, 2012 at 13:15 Comment(3)
Sorry missed your comment about framework version! I think the AllowPaging is present though?Bugger
Yeap, it is but for some reason the VirtualCount property is ignoredPetard
Have updated my answer with a 2.0+ version, Ill keep an eye out for a less invasive mechanism though! Also upvoted the question as its interesting! ;o)Bugger
U
1
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();
Undue answered 18/8, 2012 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.