ASP.NET DropDownList SelectedIndexPropriété
Contrôle DropDownList
Définition et utilisation
La propriété SelectedIndex est utilisée pour obtenir ou définir le numéro d'index de l'élément sélectionné dans le DropDownList.
Exemple
L'exemple suivant affiche le texte de l'élément sélectionné :
<script runat="Server">
Sub GetName(obj As Object, e As EventArgs)
lbl.Text = ddList.SelectedItem.Text
End Sub
</script>
<form runat="Server">
Sélectionnez un nom dans la liste :
<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="Sélectionner"
OnClick="GetName" Runat="Server" />
<br />
Le nom est :
<asp:Label id="lbl" Runat="Server"/>
</form>
Sub GetName(obj As Object, e As EventArgs)
lbl.Text = ddList.SelectedItem.Text
End Sub
</script>
<form runat="Server">
Sélectionnez un nom dans la liste :
<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="Sélectionner"
OnClick="GetName" Runat="Server" />
<br />
Le nom est :
<asp:Label id="lbl" Runat="Server"/>
</form>
Exemple de démonstration »
Contrôle DropDownList Autres extensions