A DropDownList is also commonly known as combo box. It can contain multiple data members, but in DropDownList we can choose only one value at a time. DropDownList can save a lot of GUI space as it is rendered on a Single line and is expanded only when the user clicks on the Control.

<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

DropDownList Control in ASP.Net

 Declaring a DropDownList in ASP .Net:

   A simple declaration for DropDownList can be done as below.

<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

  If we want to add some items statically it can be added inside the Page as follows.

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
      <asp:ListItem>2</asp:ListItem>
      <asp:ListItem>3</asp:ListItem>
</asp:DropDownList>

DropDownList Event :
SelectedIndexChanged event:

This event is fired when user selects any data from Drop down list.

DropDownList Control in ASP.Net

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem>Select</asp:ListItem>
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
       Label1.Text = DropDownList1.SelectedValue;
    }

When you select value in dropdownlist then selected value will show in the Label.

DropDownList Control in ASP.Net

We can change DropDownList property like forecolor,font,size etc.

<asp:DropDownList ID="DropDownList1" runat="server" Font-Bold="True" 
            Font-Italic="True" Font-Names="Arial" ForeColor="Fuchsia">
            <asp:ListItem>Select</asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
 </asp:DropDownList>

DropDownList Control in ASP.Net

  Modified On Mar-22-2018 07:29:13 AM

Leave Comment