X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

ASP.NET SelectedIndex Property


DropDownList Control Reference Complete DropDownList Control Reference

Definition and Usage

The SelectedIndex property is used to get or set the index number of the selected item in a DropDownList.


Example

The following example outputs the text of the selected item:

<script runat="Server">
Sub GetName(obj As Object, e As EventArgs)
  lbl.Text = ddList.SelectedItem.Text
End Sub
</script>

<form runat="Server">
Select a name from the list:
<asp:DropDownList id="ddList" runat="Server">
  <asp:ListItem Text="Peter" />
  <asp:ListItem Text="Lois" />
  <asp:ListItem Text="Cleveland" />
  <asp:ListItem Text="Quagmire" />
  <asp:ListItem Text="Joe" />
</asp:DropDownList>

<asp:Button Text="Select"
OnClick="GetName" Runat="Server" />
<br />
Name is:
<asp:Label id="lbl" Runat="Server"/>
</form>

Show example »

DropDownList Control Reference Complete DropDownList Control Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook