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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.

Method 3

Its realy depend/requirement on the scenario which control to be use
Listview is completely template driven and support of inserting records, you can use a regular html table and style it with CSS for presenting data, you have much control over design layout.

On the other hand GridView, you can insert records, but that can involve using
the footer and your objectdatasource_inserting event. You need to find and capture the entered data in the gridview footer then directly add into input parameters of your objectdatasource.

Method 4

ListView gives you more control over resulting HTML markup.

Method 5

Gridview is the best option. You are able to do all of the things you mentioned much easier than anyother control. A listview is derived from a ListBox

The ListView control supports the following features:

  • support for binding to data source
    controls such as SqlDataSource,
    LinqDataSource, and ObjectDataSource.

    Customizable appearance through
    user-defined templates and styles.

    Built-in sorting capabilities.

    Built-in update and delete
    capabilities.

    Built-in insert capabilities.

    Support for paging capabilities by
    using a DataPager control.

    Built-in item selection capabilities.

    Programmatic access to the ListView
    object model to dynamically set
    properties, handle events, and so on.

    Multiple key fields.


    GridView Displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control enables you to select, sort, and edit these items.

The GridView control is used to display the values of a data source in a table. Each column represents a field, while each row represents a record. The GridView control supports the following features:

  • Binding to data source controls, such
    as SqlDataSource.

    Built-in sort capabilities.

    Built-in update and delete
    capabilities.

    Built-in paging capabilities.

    Built-in row selection capabilities.

    Programmatic access to the GridView
    object model to dynamically set
    properties, handle events, and so on.

    Multiple key fields.

    Multiple data fields for the
    hyperlink columns.

    Customizable appearance through
    themes and styles.

    To learn about the other data-bound
    controls that are available in
    ASP.NET, see ASP.NET Data-Bound Web
    Server Controls Overview.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x