Here we will explain how to use DropDownList in or what is DropDownList in or how to get DropDownList selected items in with example.


  • The DropDownList control is used to create a drop-down list. It’s allowed to single select option to the user from multiple listed items. You can specify its height and width in pixel by setting its height and width but you will not be able give mutliple select option to the user from multiple listed items. When it is rendered on the page, it is implemented through <select/> HTML tag. It is also called as Combo box.

The DropDownList control support data binding. To bind the control to a data source, create a data source, such as a System.Collections.ArrayList object, that contains the items to display in the control. Then, use the Control. DataBind method to bind the data source to the DropDownList control.

Use the SelectedIndex property to programmatically determine the index of the item selected by the user from the DropDownList control. The index can then be used to retrieve the selected item from the Items collection of the control.

  • Example:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DropDownList.aspx.cs" Inherits="AspDotNet.DropDownList" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <div><b>DropDownList Demo</b></div>
                    <td>Select as Option:</td>
                        <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"
                            Height="28px" Width="100px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <td colspan="2"><b>Selected Item: </b></td>
                    <td>Item Value: </td>
                        <asp:Label ID="itemvalue" runat="server" Text="Label"></asp:Label></td>
                    <td>Item Text: </td>
                        <asp:Label ID="itemtext" runat="server" Text="Label"></asp:Label></td>



using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AspDotNet
    public partial class DropDownList : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                ArrayList list = new ArrayList();
                list.Add(new ListItem("Item1", "I001"));
                list.Add(new ListItem("Item2", "I002"));
                list.Add(new ListItem("Item3", "I003"));
                list.Add(new ListItem("Item4", "I004"));
                list.Add(new ListItem("Item5", "I005"));
                DropDownList1.DataSource =list;
                DropDownList1.DataTextField = "Text";
                DropDownList1.DataValueField = "Value";
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            itemtext.Text =DropDownList1.SelectedItem.Text;
            itemvalue.Text =DropDownList1.SelectedItem.Value;

Above example when you change selected item then called SelectedIndexChanged event where you can get selected value and text.

Let’s see output:

Use DropDownList Control in ASP.NET

Following are some important DropDownList  properties that are very useful.



Get the value of the Selected item from the dropdown box.


Gets or Sets the index of the selected item in the dropdown box.


Gets the selected item from the list.


Gets the collection of items from the dropdown box.


Name of the data source field to supply the text of the items. (No need to set when you are adding items directly into .aspx page.)


Name of the data source field to supply the value of the items. (No need to set when you are adding items directly into .aspx page.)


ID of the datasource component to provide data. (Only used when you have any DataSource component on the page, like SqlDataSource, AccessDataSource etc.)


The datasource that populates the items in the dropdown box. (Generally used when you are dynamically generating the items from Database.)


true or false. If true, the form is automatically posted back to the server when user changes the dropdown list selection. It will also fire OnSelectedIndexChanged method.


true or false. If true, the statically added item (added from .aspx page) is maintained when adding items dynamically (from code behind file) or items are cleared.


Method name that fires when user changes the selection of the dropdown box. (Fires only when AutoPostBack=true.)



I hope this will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like