views:

14

answers:

0

I am working with Gridview and implementing custom paging with PagedDataSource. there is also some search criteria in this page with which I reset the Grid with the New data according to search criteria. Problem is that sometime when I try to Bind the Grid with PagedDataSource it gives the error "Index 40 is either negative or above rows count."

Here dv.Count is 35

"Index 40 is either negative or above rows count."

Here dv.Count is 7

 "Index 60 is either negative or above rows count."

code

 pds.DataSource = dv;
 pds.AllowPaging = true;            
 pds.PageSize = 20;           
 pds.CurrentPageIndex = CurrentPage;
 lnkbtnNext.Enabled = !pds.IsLastPage;
 lnkbtnPrevious.Enabled = !pds.IsFirstPage;

 gvProducts.DataSource = pds;                                   

 gvProducts.DataBind();