Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Grid View vs. List View

What are the advantages of using listview over gridview? I need pagination, editing rows, inserting rows, and deleting rows in my view. Which control is best for that? It seems like GridView does not support data pager. What would I sacrifice if I migrated my gridviews to listviews?

like image 773
Mugunth Avatar asked May 21 '09 08:05

Mugunth


People also ask

What is the difference between list view and GridView?

The main difference between ListView and GridView is how it lays out its child. With ListView you are laying your children one by one either vertically or horizontally only. With GridView, its a combination of both. It lays its children horizontally first.

What is the difference between list view and GridView in C#?

The main difference between a ListView/GridView and a DataGrid is that the latter provides editing and sorting functionality out of the box. So if you don't require to be able to edit and/or sort the data to be displayed in a tabular grid, then choose a ListView with a GridView.

What is the difference between DataGrid and GridView?

The DataGrid and the GridView controls have different event models. The DataGrid control raises single events for operations, while the GridView control is capable of both pre-operation and post-operation events. The GridView control supports the Sorting event that occurs when a field is sorted.

Why repeater is faster than GridView?

Repeater is faster because it offers only basic data bound control rendering functionalities. If you want to show data and you don't need any complex features described below then repeater is the right joice.


2 Answers

GridView supports:

  • sorting by click
  • paging
  • editing
  • selection
  • template-based layout (rendered within <table>)

ListView supports:

  • List item
  • paging (need to use DataPager)
  • editing
  • selection
  • sorting by click (need to create an event handler manually)
  • template-based layout (rendered as you want it + provides more templates, e.g. - GroupTemplate)

The reason to use ListView would be if you need some special layout, for example, to create a table that places more than one item in the same row, or to break free from table-based rendering altogether) - which is not possible with GridView.

Using GridView on the other hand is easier and faster, so unless you need special layout to display your data, use GridView.

like image 175
niaher Avatar answered Oct 02 '22 12:10

niaher


This article is particularly useful for a comparison.

For me it is the raw flexibility of the HTML you can render. In a project I was developing I was using a GridView but replaced with the ListView as I wanted very specific paging requirements that couldn't be provided by the GridView. I could have used a 3rd party gridview to provide the paging requirements, but I wanted to minimise the reliance of 3rd party code.

The ListView alone in my opinion is a good reason for moving from ASP.NET 2.0 to 3.5.

like image 38
RichardOD Avatar answered Oct 02 '22 12:10

RichardOD