hi jbenson,
Thanks for the reply. This is an useful tip.
I'll try to explain the reason behind going for an ObjectDatasource instead of a of a regualr Dataset(Datatable). This is not a regular pagination. Even though I show pages 1..10, I get the data corresponding to one particular page at any point of time. I calculate the number of pages required for the total number of records. and display the page number accordingly on the pager. But the data displayed (in fact the data in hand) pertains only to a single page. when the user clicks on a different page number, I capture the PageIndexChanging event, get the data corresponding to that page and rebind the grid. So at any point of time i have data worth one page only. If I try to do this the conventional way, i may need to set grd.PageCount. But it is read-only ! Hence the idea of using an ObjectDatasource for binding the gird. the class (TypeName) behind the ObjectDatasource is my own class. In this case, I can set the resultset, and the totalrowsCount of the ObjectDatasource and it seems to take care of everthing else. (except what I'm looking for). May be I have to tweak the code for the ObjectDatasource's class.
Here is the code for the ObjectDatasource's Class:-
public class ItemListingDataSource
{
List<ItemListingItem> ItemList;
int totalCount = 0;
public ItemListingDataSource()
{
}
public ItemListingDataSource(List<ItemListingItem> ItemList, int totalCount)
{
this.ItemList = ItemList;
this.totalCount = totalCount;
}
public List<ItemListingItem> GetItems()
{
return ItemList;
}
public List<ItemListingItem> GetItems(int startRowIndex, int pageSize)
{
return ItemList;
}
public int TotalCount()
{
return totalCount;
}
}
and here is how I load the ObjectDatasource:-
protected void ods_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
//calling a "parametered" constructor of datasource and passing it to the ObjectInstance property
e.ObjectInstance = new ItemListingDataSource(ListingItems, TotalPages * ItemsPerPage);
}
and here is the HTML for the ObjectDatasource:-
<asp:ObjectDataSource ID="ods" runat="server" EnablePaging="true" MaximumRowsParameterName="pageSize"
OnObjectCreating="ods_ObjectCreating" SelectCountMethod="TotalCount"
SelectMethod="GetItems" TypeName=".....ItemListingDataSource">
</asp:ObjectDataSource>
Please see if you can help me in any way.
I'm glad you found where the problem is. Appreciate your help so far.
Jai