2

Im working on a grid view in asp.net mvc 3 and I need to limit the number of record that will display in my grid(not per page). Is there a way I can do that??. Thanx in advance.

dinusha87
  • 23
  • 4
  • 1
    so you want to execute the query against the datasource with a TOP X. How are you loading the data? Sql Server? EF? LINQ? – Davide Piras Oct 05 '11 at 12:15
  • no I need a way to limit the records through the controller or the gridview it self. (not using sql) – dinusha87 Oct 05 '11 at 12:25
  • 2
    can you show your controller's action code? it should be as simple as MyItems.Take(100) – VinnyG Oct 05 '11 at 13:18
  • Fixed it. Used Take() method. Thankx for your help. Any way is there a property in the grid view where we can limit the number of records?? – dinusha87 Oct 06 '11 at 04:14

1 Answers1

0

What are you using? Which GridView? It's really tough to help you whithout any detail information. But anyway, I'll try...

IMHO I wouldn't limit the number of records in the view, I would do this on the database query or whereever you get your data!

If you want to set a "JustShowMeXRecords" then put a TextBox or DropDown to your view and give this value to your controller.

If you want to have paging on your grid you can use in example this NuGet Package (http://nuget.org/List/Packages/PagedList). I use it in every project.

It has a static ans dynamic way to get this done.

Timur Zanagar
  • 323
  • 3
  • 21