GridView: How to set the number of rows to display

Jean Claude Abela picture Jean Claude Abela · Apr 19, 2012 · Viewed 82.1k times · Source

I would like my grid view to display only 3 rows any ideas on how I can achieve this?

Thanks

Answer

Tim Schmelter picture Tim Schmelter · Apr 19, 2012

Enable Paging and set the GridView's PageSize to 3.

How to: Enable Default Paging in the GridView Web Server Control

If you want to restrict your GridView to show only 3 rows without paging, you need to use a DataSource with only 3 records (f.e. via SQL-TOP-Clause or Limit in MySQL or LINQ's Take(3)).