Gridview Paging via ObjectDataSource: Why is maximumRows being set to -1?
Asked Answered
D

5

7

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?

Dolomites answered 23/5, 2010 at 23:22 Comment(5)
Just a guess, but is it possible that your data source is unable to report a total row count?Bethannbethanne
This is before it even hits the DB. The maximumRows parameter simply limits the number of rows returned in the select statement. My understanding is the Gridview supplies the maximumRows parameter to the ODS, the ODS sends it along to the middle tier, and finally the business object passes it to the sproc to get the right number of records back from the DB. This parameter should be analogous to whatever has been set in the GridView's PageSize property. I know things are wired because as I said... the StartRowIndex (which also orginates from the GridView) is being passed through just fine.Dolomites
I'm getting the -1 value in the middle tier prior to making the DB call. My conclusion is that for some reason either the ObjectDataSource or GridView are not sending the proper value. I don't get it though because all the samples make it look like a no brainer... and there is no mention of anyone else having this problem. Stupefying. I figure I'm missing something... but I've checked & re-checked and it seems like everything is in place.Dolomites
msdn.microsoft.com/en-us/library/… this seems like it has some relevance... but I can't find a smoking gun. The table I'm targeting has 26 rows, and I'm asking for a page size of 10 records. Why whould it throw an ArgumentOutOfRangeException? If it was throwing this exception then it should be caught and displayed by my try / catch wrapped around the page_load in which all of this is occuring. Instead... a -1 PageSize is being passed to the middle tier with no exception.Dolomites
please put "C#" in the tags, not in the titleStansberry
W
6

If SelectCountMethod is not specified the PageSize will be -1.

Wandering answered 6/1, 2011 at 16:4 Comment(1)
Thanks, this solution saved me a lot of time. It's not that obvious.Rostock
A
2

I think you might be a bit confused (I was reading this) between pages and rows.

The parameters used by ObjectDataSource (ODS) for paging are the properties startRowIndex and maximumRows but in your function you call them PageIndex and PageSize.

ODS displays in pages but uses row numbers for displaying the pages. For example, which a page size of ten (the default) the first call to your GetProducts() function will have startRowIndex = 0 and maximumRows = 10 - that is start at row zero and provide ten rows.

If the user selects page 2, then GetProducts is called with startRowIndex=10 and maximumRows = 10. For page 3 this would be startRowIndex = 20 and maximumRows = 10

I suggest you rename your parameters to use the same names - it will make coding easier.

Alloy answered 23/11, 2012 at 16:59 Comment(0)
P
0

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.

Peterkin answered 9/6, 2010 at 16:34 Comment(0)
H
0

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

Halleyhalli answered 8/7, 2010 at 13:29 Comment(0)
S
0

You need to set the SelectCountMethod property in the ObjectDataSource control, also set the pagersize and index there, hopefully this will resolve the issue.

Regards, Joy

Sorrow answered 31/1, 2011 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.