How to bind GridView and DropDownList controls using DataTable object
Author: Faraz
Download Source Code : 278_DataReaderandWebControls.zip
In this article I will try to explain you the technique of binding GridView and DropDownList control using DataTable object.
In .net framework 1.0, we have DataSet class which helps the developers in managing their data even when it is disconnected form the data source. Objects that are created using DataSet class works as a container for the the other objects that are created from the DataTable class. DataTable object creates a logical table in memory and most of the programming with the disconnected data is done using one or more DataTable objects. However, the .net framework 1.0 did not allow you to work directly with the DataTable objects. The limitation in using this object is you need to use the DataSet object to perform any operation on the DataTable. But it is not the case with .net framework 2.0. In ADO.Net 2.0 remove this limitation and allow you to work directly with the DataTable object.
In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.
To begin with, create new website in VS2005 adds the two controls; GridView control:
And the second control is DropDownList control. You can add text before these controls using Label control or simple a span tag: