ASP.NET DropDownList
The DropDownList is a web server control which is used to create an HTML Select component. It allows us to select an option from the dropdown list. It can contain any number of items
ASP.NET provides a tag to create DropDownList for web application. The following is the Syntax of DropDownList tag.
ASP.NET DropDownList Example
We are creating DropDownList by using Visual Studio 2017. This example includes the following steps.
Create a Web Form
Add a new form by specifying its name.
Initially, it is an empty form. Now, we will add a new DropDownList by dragging it from the toolbox.
After dragging, our web form looks like the below.
Now, to add items to the list, visual studio provides Items property where we can add items. The property window looks like this.
Click on the items (collection) and it will pop up a new window as given below. Initially, it does not have any item. It provides add button to add new items to the list.
Adding item to the DropDownList, by providing values to the Text and Value properties.
We have added more items to it and now, it looks like the following.
After clicking OK,
DropDownListExample.aspx
// DropDownListExample.aspx.cs
Output:
At server side, selected city is fetched and display to the user.