ASP.Net DropDownList OnSelectedIndexChanged Event
The OnSelectedIndexChanged event handler of ASP.Net DropDownList control enables you to handle the click event of list item at server side that is raised at the time when user clicks to select a list item of dropdownlist control. The SelectedIndexChanged event of DropDownList control occurs only if the AutoPostBack property of dropdownlist is specified with value "true". The SelectedIndexChanged event occurs immediately when the index of the selected list item of the dropdown list item changes and it submits the web form to the server only if its AutoPostBack property has value "true". You can handle the event at server side using C# code and apply the custom logic there to execute any specific action based on the value of select item of the dropdownlist menu.
DropDownList Control Examples:
You can see the live samples and examples of DropDownList Control from the following links:
Sample Code for ASP.Net DropDwonList OnSelectedIndexChanged Event
HTML Code
<asp:DropDownList ID="DropDownList1"
runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="item 1"></asp:ListItem>
<asp:ListItem Value="item 2"></asp:ListItem>
<asp:ListItem Value="item 3"></asp:ListItem>
<asp:ListItem Value="item 4"></asp:ListItem>
<asp:ListItem Value="item 5"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
In the above sample code for DropDownList control we have specified the AutoPostBack property value as "true" and also OnSelectedIndexChanged server side event is used to handle the click event of dropdown list item when user clicks an item to select it.
You can attach the SelectedIndexChanged of dropdownlist control in two ways as follows:
1. Double clicking the dropdownlist control for which you want to generate the server side OnSelectedIndexChanged event handler. In this tutorial we have also used the same approach to handle the SelectedIndexChanged event of dropdownlist control.
2. You can also attach the SelectedIndexChanged event programmatically in the page load method of ASP.Net web page E.g.:
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
}
void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
When you will write the ID of the dropdownlist control inside the Page_Load method for example DropDownList1, and will type the "." Dot operator it will display the list of properties and methods of dropdownlist control. Select the SelectedIndexChanged event from the intellisense and press "+=" and then tab key from the keyboard. It will generate the event handler automatically.
C# code
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedValue;
}
In the above C# sample code for SelectIndexChanged event handler of ASP.Net DropDownList control we have used the SelectedValue property to get the value of the select item. When user will click on any list item of dropdownlist menu it will raise the SelectedIndexChanged event that will execute the above specified code to get the value of selected item.
Output:
Get the output for above discussed code from the following link:
Continue to next tutorial: ASP.Net DropDownList SQL Datasource Databinding to learn how to display the data retrieved from the SQL database as list items of dropdownlist control.

Thanks