ASP.NET SelectedIndex 属性

คำนิยามและการใช้งาน

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="Select"
OnClick="GetName" Runat="Server" />
<br />
ชื่อคือ:
<asp:Label id="lbl" Runat="Server"/>
</form>

ตัวอย่าง

เอาข้อความออกมาจากส่วนของ DropDownList หนึ่ง