DropDownList selectedindexchanged get selected value
DropDownList is an asp.net list web server control that allow us to select a single
item from a drop-down-list. the following asp.net c# example code demonstrate us how can
we get dropdownlist selected item's value when users change selection in dropdownlist control.
if we set the dropdownlist control's AutoPostBack property value to True and write an event handler for SelectedIndexChanged event, we can get the users selected item value immediately when they make changes on dropdownlist item selection.
SelectedIndexChanged event is raised when the dropdownlist control item selection changes between posts to the server. AutoPostBack property get or set a value indicating whether a post back to the server automatically occurs when the user changes the dropdownlist item selection.
we can determine which item is currently selected in dropdownlist control using SelectedIndexChanged event's EventArgs object. by using this EventArgs object we can get the dropdownlist selected item's value.
if we set the dropdownlist control's AutoPostBack property value to True and write an event handler for SelectedIndexChanged event, we can get the users selected item value immediately when they make changes on dropdownlist item selection.
SelectedIndexChanged event is raised when the dropdownlist control item selection changes between posts to the server. AutoPostBack property get or set a value indicating whether a post back to the server automatically occurs when the user changes the dropdownlist item selection.
we can determine which item is currently selected in dropdownlist control using SelectedIndexChanged event's EventArgs object. by using this EventArgs object we can get the dropdownlist selected item's value.
dropdownlist-selectedindexchanged-get-selected-value.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = "you selected....<br />";
Label1.Text += "item: " + DropDownList1.SelectedItem.Text;
Label1.Text += "<br />value: " + DropDownList1.SelectedItem.Value;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net dropdownlist selectedindexchanged get selected value</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - dropdownlist
<br />selectedindexchanged get selected value
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="select an item from dropdownlist."
BorderColor="HotPink"
BorderWidth="1"
Font-Size="X-Large"
Width="350"
>
</asp:Label>
<br /><br />
<asp:DropDownList
ID="DropDownList1"
runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
>
<asp:ListItem Text="Canada Goose" Value="1"></asp:ListItem>
<asp:ListItem Text="Cackling Goose" Value="2"></asp:ListItem>
<asp:ListItem Text="Hawaiian Goose" Value="3"></asp:ListItem>
<asp:ListItem Text="Black Swan" Value="4"></asp:ListItem>
<asp:ListItem Text="Whooper Swan" Value="5"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>


- How to set a default value for DropDownList
- How to add an item at the top of DropDownList
- How to add an item at DropDownList at index 0
- How to add an item to DropDownList after databind
- How to add a blank item at the top of DropDownList
- How to reset DropDownList on postback
- How to get DropDownList selected item without postback
- How to add CSS class to DropDownList each items
- How to change DropDownList alternate item color
- How to change DropDownList selected item color