Conclusion: databound controls

In this tutorial, we looked at ASP.NET's support for databound controls. While it's not rocket science to iterate through a collection and add the data to ASP.NET's server-side controls, it's a fairly common operation. That Microsoft pushed it down into the Framework classes is a good thing.

One of the advantages of these controls is that they don't care at all where their data comes from. The data might be as simple as an ArrayList composed of .NET types (with each element in the array representing a row and each property representing a column). On the other hand, the data bound to a control might be as complex as IDataReader or a DataSet acquired from a physical database.

Looking at databound controls invariably involves mentioning the ASP.NET database story: ADO.NET. The ADO.NET managed classes are for connecting to the database, commanding the database, and harvesting the results afterward. While connecting to the database manually (via .NET 1.x-style code) is still supported, .NET version 2.0 and Visual Studio 2005 offer an easier way to associated controls with data via the DataSource controls.

ASP.NET includes a number of databound controls that may be matched up with a collection or (in the case of certain DataSource controls) a data source. The controls then assume the burden of iterating through the data and rendering the correct tags to the client.

Tutorial 11 Quick Reference

How to bind a collection to a control

Set the control's DataSource property to the collection

How to choose a column to display in the control

Set the control's TextTextField property to the column name

How to choose a column to use programmatically (that's NOT displayed in the control)

Set the control's TextValueField property to the column name

How to display a DataTable as a grid

Use the DataGrid or the GridView controls

How to display a DataTable as a formatted, repeating list

Use either the DataList or the Repeater

How to make a class' member variables available as DataTextFields and DataValueFields within a control

Expose the members as properties

by BrainBellupdated