Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview disappears on postback when paging is enabled

I have a gridview that has its DataSourceID property set to a custom ObjectDataSource object. When AllowPaging is set to True, the GridView disappears after a postback. If I set AllowPaging to False it's fine. Can someone shed some light on this for me? :)

Edit: The other thing I'm confused about is I thought that if you set the DataSourceID that the grid would get data from the datasource whenever it needed it. If the grid is disappearing because it's not holding the data, why isn't the gridview getting the data it needs from the datasource?

like image 530
adam0101 Avatar asked Oct 14 '22 16:10

adam0101


1 Answers

It's possible that after the postback occurs the datasource is not being maintained or refilled and there are no items to populate the grid. Are you handling state correctly for the datasource object (rebinding/keeping the source alive) when paging is enabled?

This may sound like a vague answer, but without an example of how the source is getting the data it's kind of hard to diagnose why the items would be gone.

Edit:
The method I was thinking of was for callback paging/sorting. However I did find some info ont he ODS & Paging.. make sure you have set the following:

  1. GridView: AllowPaging and off course you need to set PageSize.
  2. ObjectDataSource: EnablePaging, also you need to set the:
    • MaximumRowsParameterName="maxRows"
    • StartRowIndexParameterName="startRowIndex"
    • SelectCountMethod="RecordCount"

I think you only need to set the 3 sub items of item 2 if you want to handle paging size etc manually.

Then you can read more up on this here.

like image 171
Quintin Robinson Avatar answered Nov 09 '22 08:11

Quintin Robinson