views:

237

answers:

3

So before I tried custom gridview paging via ObjectDataSource... I think I read every tutorial known to man just to be sure I got it. It didn't look like rocket science.

I've set the AllowPaging = True on my gridview.

I've specified PageSize="10" on my gridview.

I've set EnablePaging="True" on the ObjectDataSource.

I've added the 2 paging parms (maximumRows & startRowIndex) to my business object's select method.

I've created an analogous "count" method with the same signature as the select method.

The only problem I seem to have is during execution... the ObjectDataSource is supplying my business object with a maximumRows value of -1 and I can't for the life of me figure out why. I've searched to the end of the web for anyone else having this problem and apparently I'm the only one. The StartRowIndex parameter seems to be working just fine.

Any ideas?

A: 

You are not alone. I have the same problem. My setup is a bit different. In my case I am using a ListView instead of a GridView Control. I got 2 pages, one using a ListView and DataPager and the other using a ListView and a Custom Navigation Control(this is in essence the same as the DataPager just different Markup output). Both pages use the same BLL Method and set the maximumRow & startRow in the same way. Basically copy&pasted code.

The ListView-DataPager setup works fine, parameters are set correctly in the BLL Method. The page without DataPager fails. But the DataPager can't be the reason. Both (DataPager and my Custom Control) produce the same, expected values which are passed to the ObjectDataSource parameter collection.

The most confusing thing is, that the SelectCountMethod, which is called after the SelectMethod, gets the correct parameters in both versions!

I was able to work around this problem by setting the parameter values in the OnSelecting Event of the ObjectDataSource:

protected void ObjectDataSource_MyListing_OnSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
            e.Arguments.StartRowIndex = m_startRowIndex;
            e.Arguments.MaximumRows = m_PageSize;
}

I read somewhere that the -1 value for MaximumRows just means "all Remaining Records". So it wouldn't be an error but a default value.

This is my first post here, hope I didn't do anything wrong since this isn't really a solution. Also I don't want to hijack but I would appreciate any additional information ... this problem is bugging me.

Erik
A: 

This work around is working.

I was also stuck up with the same problem.

When you make

EnablePaging = "true" then StartRowIndex was getting set to the page size. if EnablePaging = "false" then MaximumRows was set to zero.

However if you set the e.Arguments.StartRowIndex = m_startRowIndex; e.Arguments.MaximumRows = m_PageSize; Then it is working properly, However this is a workaround

Dhinesh Muthuvel
A: 

Do u provided the select count method in the object data source ,I was also getting the same error .I corrected it by adding select count method to object data source,

R u using the datapager or not?

RanjeetAulakh