Learn ASP.NET 2.0 - Intro to the Grid Control
Part 1 - A "From the Ground Up" Tutorial - Programming for the networked world.
Databound Controls
In the previous parts of this tutorial, SQL statements were included directly in the VB.NET source code. This is the "old school" way to access a database, loved by those who want more immediate control over what the program is doing. You can see more clearly what's happening.
For the rest of us, there are "databound controls". The idea is that the control on the web page is linked to a data source. That makes these controls into bundles of power that can retrieve, update, format, and save records from a database or even XML from a document. ASP.NET 2.0 includes these databound controls:
GridView
Best for displaying data from a database table. You can display, sort, select, and edit the data.
DataList
This control requires the use of a "template" to format the layout and appearance of the list. Templates can contain a mix of HTML syntax, Web controls, and databinding syntax.
Repeater
A control that you use when you need to determine the final layout. A Repeater doesn't create a table by default.
Templates and markup separate one row from the next.
(If you have used databound controls before and you're looking for the DataGrid control, it's not here anymore. The GridView control has replaced it in ASP.NET 2.0. Technically, it's still available for backward compatibility, but Microsoft recommends that you use GridView instead.)
The AVBAsk website developed earlier adds records to a database table (and sends email at the same time). The next, obvious thing for it to do is display a list of the messages that have been sent. In this segment of the tutorial, a new page will be added to the website to display a GridView control bound to three of the columns in the AVBQuestion table.
One column in the database, for the message text, might be too long to display in the GridView control since the message could be several pages long. The default way to bind data to columns in the control doesn't do the job in this case, but there's another way (new in ASP.NET 2.0) to do the job that lets you do just about anything you can think of in the GridView cells. We'll check it out too.
So ... fire up Visual Web Developer (VWD from now on) and lets go.