ASP.NET Dropdown List Control: Eight Ways to Bind Data
(Page 1 of 4 )
This article shows you the real power of a dropdown list control available in ASP.NET. It also explains eight methods of binding data to the dropdown list.
A downloadable file for this article is available
here.
The sample downloadable solution (zip) is entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that it would work with other versions of Windows (which support .NET 1.1) as well.
What are the ways to bind data to a drop down list?
I don’t think there exists any meaningful application which does not have at least one “dropdownlist” control. Every user definitely knows what a “dropdownlist” is. The most important issue is that a “dropdownlist” can maintain two sets of values inside.
The first set of values display generally the “textual” information (which is visible to the user). The second set of values is “hidden” from the user. The user would never know about the “hidden” information. This flexibility is particularly necessary when you want to display only “student names” to the user and work with “regdno” behind the scenes. Of course, the user may not identify any student just with the “regdno”!
Not every scenario needs the two sets of values. Some may need only one set of values (both “text” and “value” would be the same). The “dropdownlist” control in ASP.NET supports both of these scenarios.
The process of attaching the “dropdownlist” control to a source of data is nothing but “data binding.” This process of “binding” can occur in several ways including databases, arrays, and so on. In this article, we will mainly look at the following ways to bind (or place) information into a “dropdownlist” control.
- Binding to a Simple Array
- Binding to an ArrayList
- Binding to a hashtable
- Binding to a data table
- Binding to a data set
- Binding to a data view
- Binding to a set of objects
- Binding manually
The above are the most frequently used “data binding” mechanisms when we work with a “dropdownlist” in ASP.NET. Now, let us go through each of those methodologies.
Next: Binding to a Simple Array >>
More ASP.NET Articles
More By Jagadish Chaterjee