Using the DataGrid ItemDataBound Event

The DataGrid is of course probably the most popular and most implemented GUI control in ASP.NET 1.x. One of the fun parts of working with this control is the level of flexibility it brings developers allowing for unlimited combinations of creative implementations.

By applying different design patterns to the built-in functionality you can develop truly unique, robust, user friendly interfaces that allow your users to quickly and easily locate and manipulate the information in the application.

As you work with such a large scale component such as the DataGrid you will learn more and more about the capabilities over time. As your knowledge increases so does the complexity of your WebForms. Before long the amount of code in your code-behind files starts to exceed even your business tier or database tier logic.

Learning development pattern tricks to help manage the amount of code you develop is important in application maintenance. How many times have you come back to a WebForm a few months after you developed it and had to read the code for 30 minutes before you remembered what you did? This is a common occurrence in a lot of applications that don’t employ development standard patterns. Or worse yet, if you did not author the code yourself it can take you hours of research to unearth the processes behind other developers` code.

The purpose of this tutorial is 2-fold. First, we will look at a simple yet extremely helpful development pattern to help manage the columns in a DataGrid control. And second, we will look at how to implement correctly the ItemDataBound event of the DataGrid control to implement some advanced user interface display elements.

Note: Visual Studio .NET 2002/2003 running ASP.NET 1.x is required for this tutorial. Both VB.NET and C# code samples will be provided

Kevin Koch is a senior software engineer with over 8 years experience designing and architecting primarily web based applications. Fresh out of college during the nineties he co-founded Task Solutions and developed several projects with the then popular classic ASP.

During the Dot Com boom Kevin left his position as president and joined a new venture to build an enterprise insurance claim system build upon J2EE technology. After the Dot Com crash Kevin schooled himself to become an expert with .NET technology and is currently freelancing his ASP.NET skills to build enterprise n-tier frameworks using advanced OO methodologies.