O'Reilly logo

Programming ASP .NET by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The DataGrid Control

The problem with pre-designed user controls is typically that they are either simple and therefore too limited to do what you want, or they are powerful and therefore so complex that they are very difficult to learn. The DataGrid control attempts to overcome both of these constraints. Creating a simple DataGrid control couldn’t be much easier, yet there is enough power and complexity to keep you quite busy tweaking and modifying the control to do exactly what you want.

To explore both the simplicity and the power of the DataGrid control, we’ll use the process of successive approximation to get something working quickly and then to keep it working while we enhance it.

Version 1: Displaying Data

In the first iteration, you’ll create a DataGrid object and display some simple data. To get started, you need a data source, in this case an ArrayList that you’ll populate with Bug objects. You will define the Bug class, and each Bug object will represent a single bug report. For now to keep it simple, you’ll give the Bug class a few fields to hold representative information about a given code bug. Example 10-1 is the definition of the Bug class in C#; Example 10-2 is the same definition in VB.NET.

Example 10-1. The Bug class in C#

public class Bug { private int bugID; private string title; private string reporter; private string product; private string version; private string description; private DateTime dateCreated; public Bug(int bugID, string title, string reporter, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required