ASP.NET DropDownList SelectedIndex 屬性
DropDownList 控件
定義和用法
SelectedIndex 屬性用于獲取或設(shè)置 DropDownList 中被選項(xiàng)目的索引號(hào)。
實(shí)例
下面的實(shí)例輸出了被選項(xiàng)目的文本:
<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>
演示實(shí)例 ?
DropDownList 控件
更多建議: