BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
With the introduction of the ListView data control in ASP.NET 3.5, there are now 4 separate tools for displaying multiple rows of data in ASP.NET. Which one is best - GridView, Repeater, DataList or ListView?
Posted by Andy Brown on 19 September 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
GridView Controls in ASP.NET
The GridView is the grandaddy of all ASP.NET controls. If you want to become a serious ASP.NET developer, you're going to have to learn all about it.
This blog just gives an overview of the GridView control - I'll try to write a much more detailed blog on it in the near future!
Example of GridView Control
Here's an example of a GridView control:
This GridView contains 3 columns (the third one is a template field containing an edit button). We've put the GridView in a DIV tag to enable scrolling.
The HTML Source for this GridView
The source HTML for the gridview above is as follows:
The source HTML for this GridView
The formatting for the GridView has been done via styles and skins (not shown here). You can find out how to do this on our basic ASP.NET courses.
To get some idea of how powerful a GridView is, here is a partial list of events supported by a GridView:
Some of the events supported by a GridView (they're in alphabetical order, so only the second half of the list is shown here).
For nearly all ASP.NET web pages displaying sets of records, a GridView is the way to go. GridViews support:
- Automatic sorting (click on a column heading to sort by that column)
- Automatic paging (sort of - true paging is only possible if you use more complicated data sources)
- Editing and deleting of data
- Selection of rows
The only thing a GridView doesn't support is inserting rows: for this you are best of using a FormView or DetailsView control.