مشخصه SelectedIndex ASP.NET

تعریف و استفاده

مشخصه SelectedIndex برای دریافت یا تنظیم شماره‌ی فهرست مورد انتخاب در DropDownList استفاده می‌شود.

مثال

در اینجا مثالی آورده شده که متن مورد انتخاب را چاپ می‌کند:

<script runat="Server">
Sub GetName(obj As Object, e As EventArgs)
  lbl.Text = ddList.SelectedItem.Text
End Sub
</script>
<form runat="Server">
یک نام از لیست انتخاب کنید:
<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="انتخاب"/>
OnClick="GetName" Runat="Server" />
<br />
نام است:
<asp:Label id="lbl" Runat="Server"/>
</form>

مثال

متن یک مورد از DropDownList را دریافت کنید