asp.net - How to use DropDownList SelectedIndexChanged event

DropDownList SelectedIndexChanged Event
DropDownList is an asp.net list web server control that allow users to select a single item from a drop-down-list. asp.net developers can automatically post selection to server when user changes selection on dropdownlist. for that developers need to set dropdownlist AutoPostBack property value true. programmers also need to write an event handler for SelectedIndexChanged event.

SelectedIndexChanged event raised when user changes selection on dropdownlist items.. dropdownlist must persist some values between posts to the server for SelectedIndexChanged event to work correctly.

following c# asp.net source code demonstrate us how can we use dropdownlist SelectedIndexChanged event.
DropDownListOnSelectedIndexChanged.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        Label1.Text = "You Selected Color: " + DropDownList1.SelectedItem.Text;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use DropDownList SelectedIndexChanged event</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">DropDownList: OnSelectedIndexChanged</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="DodgerBlue"
             Font-Size="Large"
             >
        </asp:Label>
        <br /><br />
        <asp:Label 
             ID="Label2"
             runat="server"
             Font-Bold="true"
             ForeColor="SeaGreen"
             Text="Color List"
             >
        </asp:Label>
        <asp:DropDownList 
             ID="DropDownList1"
             runat="server"
             AutoPostBack="true"
             OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
             BackColor="Crimson"
             ForeColor="FloralWhite"
             >
             <asp:ListItem>AntiqueWhite</asp:ListItem>
             <asp:ListItem>Aquamarine</asp:ListItem>
             <asp:ListItem>BlanchedAlmond</asp:ListItem>
             <asp:ListItem>BlueViolet</asp:ListItem>
             <asp:ListItem>CornflowerBlue</asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>
More asp.net examples