views:

1130

answers:

2

Hi. I have a Gridview, which is bound to an IList. I'd like to have paging " the safer way" (only fetching the Items I Need), so I created a metod on my repository like this

public Ilist<Item> GetItems(int from, int number){ ... }

The thing is that wheen I bind it, it only shows me the n items, and doesn't show the paging controls. I tried to find the way to tell the gridview how many elements I have on my resultset with

public int CountItems{ get{ ... } }

but I didnt find a place to tell the GV this value.

What is the strategy here? Is it necessary to have an ObjectDS? I refuse to belive so!

What can I do to have Paging?

A: 

Unfortunately you do need an Object DataSource or implementing a custom datasource. Here is a link to the msdn doc that mentions it http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx. Datagrid did supported doing what you want, but ms didn't do the same for GridView.

I guess an option would be to create some kind of dummy custom datasource, that would expose the methods/events that you need to still control the process outside of it.

eglasius
not the answer I was expecting, But hey! what can U do??Thnks!!!!!
Nicolas Irisarri
A: 

I also encountered the same problem when implementing paging in an ASP.NET gridview using NHibernate. This is a frustrating limitation of GridView if you implement your own paging functionality.

At the time, the only three options I saw were:

  1. create separate user control that implements custom navigation functionality that interfaces with the GridView control
  2. create a derived class that inherits from GridView control and add custom navigation functionality
  3. use ObjectDataSource

I went with a basic implementation of # 1 since it was simpler to do than # 2 and much more preferable than using # 3 which would not have meshed well with the model-view-presenter pattern we were using on the project (as well as making unit testing more difficult).

Ray Vega