Same problem. However, I do not use the SPGridViewPager control. I just call .PageIndex = e.NewPageIndex; Both are of type Integer. I am doing the assignment in the PageIndexChanging(object sender, GridViewPageEventArgs e) method PageIndexChanging(object sender, GridViewPageEventArgs e) .
Not sure what is happening at this moment. Now I look at it in Reflector.
I was wondering if you are using DataKeys? It looks like there are 2 throws. See below.
public override void set_PageIndex(int value) { int pageIndex = this.PageIndex; DataKeyArray dataKeys = this.DataKeys; base.PageIndex = value; if (pageIndex != this.PageIndex) { this.PreviousPageIndex = pageIndex; if ((dataKeys == null) || (dataKeys.Count <= 0)) { this.PreviousPageFirstRowDataKey = null; this.PreviousPageLastRowDataKey = null; } else { **this.PreviousPageFirstRowDataKey = (string) dataKeys[0].Value; this.PreviousPageLastRowDataKey = (string) dataKeys[dataKeys.Count - 1].Value;** } } }
To fix this, I had to study my data source and datakeys more closely. I have a set of records returned from SQL Server, and what I do is bind them to POCO. This class had several public properties of type Integer. These integers were my datakeys on the grid. Instead, I replaced their type with a string to get around the casting issue.
Hope this makes sense. He fixed it for me.
source share