Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Unassigned: Setting WebGrid PageIndex throws ArgumentOutOfRange exception when there are no items in the list [1509]

$
0
0
Ported from https://aspnet.codeplex.com/workitem/10352

This is a minor one, but I thought that I would put it in since I have it in my head.

The following code throws an ArgumentOutOfRangeException with message "Value must be between 0 and -1. Parameter name: value if there are no items in the list that is bound to. " The exception is thrown for any value of pageIndex, including 0 and -1.

```
grid.PageIndex = pageIndex
```

I think that you should be able to set the page index to 0 if there are no items in the list so that there don't need to be special cases in user code as I have now:

Now I have:
```
if( Model.TotalItems > 0 )
{
pageIndex = Model.PageNumber - 1;
grid.PageIndex = pageIndex;
}
```
I should only need (note Model.PageNumber is always > 1, so pageIndex will be 0 even if there are no items):
```
pageIndex = Model.PageNumber - 1;
grid.PageIndex = pageIndex;
```

Viewing all articles
Browse latest Browse all 7215

Trending Articles