Displaying tabular data to the users is one of the common
tasks we will perform in any site we build. In ASP.NET 1.x we make use of the
DataGrid, DataList and Repeater controls most of the time depending on the
need. With the introduction ASP.NET 2.0, we have GridView in the place of DataGrid
with some changes that make the control more easily usable than DataGrid with
the help of data source controls. Each time the need of displaying the data
will be different. Sometimes, we will require the data to be displayed to the
user where he/she should have edit/update/delete functionalities or we require
displaying the data with the header being displayed in the left as opposed to
top which makes us decide which of the above controls to use. Coming to our
subject, most of the time it is sufficient if we drag the control into the
WebForm instead of adding it dynamically to achieve the target. At times we
will require doing this dynamically which I took to discuss in this article
with both DataList and GridView control in ASP.NET 2.0.
Microsoft has designed both of the controls in such a way so
that the developer can use the flexibility and can build it dynamically by
giving dynamic styles and layouts to the data display. Moving forward I will
explain a scenario where we can have a dynamic DataList/GridView and construct
it.