Link to home
Start Free TrialLog in
Avatar of perksdev
perksdev

asked on

GridView doesn't refresh paging when ObjectDataSource returns empty collection.

I have an ASP.Net 3.5 web page with a GridView that's bound to an ObjectDataSource.  Paging and sorting have been enabled and everything works fine when the DataSource returns data.  In certain instances when the DataSource returns null or an Empty collection, the GridView retains the paging from the previous Select instead of hiding the GridView due to an empty result set.

I have a parameter being passed to the ObjectDataSource that can be used to filter the results.  When this parameter causes the DataSource to return null or an Empty collection, the paging doesn't reset.  I have checked that the Select Method used by the ODS is actually returning and empty collection (List<>) and that the Count Method used by the ODS is returning zero.

If I click the search button a second time, the GridView becomes hidden as I would have expected it to do the first time.

If I need to give more information I would be happy to, but that I think that sums up the problem for now.

Any help is greatly appreciated.  Thanks.
Avatar of Bembi
Bembi
Flag of Germany image

Not quite sure about the internal of this GridView, but if the recordset is empty, nothing is delivered to the Grid and it may be  that the gridview does't initiate a refresh. I has similar things with several gridview controls.

Whats about (as you said you have a button for searching) to refresh the gridview after the user has pressed the button, or to check the result before and then clear the grid if the result is empty.  
ASKER CERTIFIED SOLUTION
Avatar of funwithdotnet
funwithdotnet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of perksdev
perksdev

ASKER

While I still would have liked to get the GridView working properly (showing EmptyData Template/Text), this workaround is what I ended up going with.

Thanks.