ASP.Net DropDownList Control

Updated on 04 Jul 2012,
Published on 28 Oct 2009

The ASP.Net DropDownList control provides the functionality to display a single select list of items in the form of drop down menu. It does not allow the user to select multiple items at different indexes and enables you to get or set the single selected index of the DropDownList control to store it into the data store according to the user input. You can display a long list of items in the ASP.Net DropDownList control and adjust its height and width using CSS styles or its inbuilt properties that enable you to specify its height and width. Some browsers do not support the height parameter and display the length of DropDownList based on their instruction sets.

The ASP.Net DropDownList control consists of following properties that are commonly used to get or set the list item values or user input. It also includes the two types of property sets that allow you to customize the look of the DropDownlList control and bind the list items to it for displaying the single select list of items on the web page. Following properties allow you to get or set the list items of ASP.Net DropDownList control:

AppendDataBoundItems: It allows you to add the list items of DropDownList along with the data-bound list items retrieved from any data source. It is a Boolean type property allows or disallows the append feature of list items based on its true or false value.

AutoPostBack: It is also a Boolean type property that enables the control to send the web page to PostBack when user clicks the dropdownlist list item to select it from the drop down menu.

DataMember: It accepts the name of one of the data table stored in the data source, if there is a collection of data tables in it. For example, using SQL queries or stored procedures you can fetch the data in the form of multiple data tables that can be stored into a DataSet class object. This DataSet object can be used to bind the data to different types of Data-bound controls. The DataMember property enables you to specify the name of the table that you want to bind with any data-bound control or DropDownList control that also support data binding feature.

DataSource: This property allows you to specify the name of the data source dynamically.

DataSourceID: It accepts the ID of the DataSource control such as SqlDataSource, XmlDataSource control etc. used to retrieve the data from the database.

DataTextField: It accepts the name of the Field/Column of the data table stored in the datasource object that you want to display as the text content of the dropdownlist items.

DataTextFormatString: It allows you to format the text property of the dropdownlist item. For example you can use {0:C} to format the numeric value as currency. There are different types of formats such as {0:X}, {0:E}, {0:N}, {0:C}. You can learn about these formats from this tutorial: ASP.Net C# String Format Function

DataValueField: It accepts the name of the field of the data table stored in the datasource object that you want to set as the value attribute of each list item of dropdownlist control. This value part does not appear as text content.

Items: The Items property provides an easy way to add the list items manually. It allows you to generate the collection of list items using a dialog box that auto generates the HTML markup code at the back ground.

Other than above properties of ASP.Net DropDownList control that allow you to populate it with list items, it also contains few CSS based style properties that allow you to customize the appearance of control and its fonts. The DropDownList control supports BackColor, CssClass, Font style properties, ForeColor, Height and Width property. The Font style properties include Bold, Italics, Name, Underline, Size, and StrikeOut like properties that enable you to change the appearance of text displayed as list items of DropDownList.

Continue to the next tutorial: ASP.Net DropDownList AutoPostBack Property to learn the use of AutoPostBack property that submits the web page when user selects an item of dropdownlist control.

0 Responses to "ASP.Net DropDownList Control"
Leave a Comment
* required
* required
* will not be published
* optional
* hint:
  • Subscribe via Email