Wednesday, June 20, 2007

Developer Guide: ASP.NET Grid View Part 1

I've decided to start collecting my accumulated knowledge regarding the ASP .NET GridView control. This is really for my own edification because I killed to many brain cells in college and now I can't keep everything in my head anymore. However, I do hop e that someone finds this useful so I'm going to try and write it at a fairly high level over a series of posts. I plan on covering the following topics:

  1. What is the GridView control

  2. Common Properties

  3. The Columns collection

  4. GridView events - what you absolutely need to know

  5. Tricks of the Grid

The GridView Control

The GridView control is an ASP.NET control for formatting a set of data in a consistent manner. In web development the most common task asked for is the layout the results of a database query into a table on screen and allow the user to interact with that data. This used to involved tons of code, paging routines, and it caused a huge mess.

The GridView control simplifies this way, way, down while still allowing you some very fine grain control. At its most basic a GridView control requires 1 markup line and 3 code behind lines.

Markup:


Code Behind:
string sql = "Query"
GridView.DataSource = Your.DataAccessLayer.QueryAsDataTable(sql);
GridView.DataBind();

Done. Yeah, yeah I took a shortcut and ignored things like in-page DataSources and I didn't actually tell you how to build your Data Access Layer, but these are things I wax poetic on later.

No comments: