ASP.NET DropDownList SelectedIndexPropiedad


DropDownList 控件Control DropDownList

Definición y uso

La propiedad SelectedIndex se utiliza para obtener o establecer el número de índice del elemento seleccionado en DropDownList.


Ejemplo

El siguiente ejemplo muestra el texto del elemento seleccionado:

<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>

Demostración »

DropDownList 控件Control DropDownList Otras extensiones