ASP.NET DropDownList SelectedIndex 属性
ASP.NET DropDownList SelectedIndex 属性
DropDownList 控件定义和用法
SelectedIndex 属性用于获取或设置 DropDownList 中被选项目的索引号。
实例
下面的实例输出了被选项目的文本:
<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>
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>
演示实例 »
相关文章
- ASP.NET Web Pages WebSecurity 参考手册
- ASP.NET Web Pages WebMail 参考手册
- ASP.NET Razor 标记
- ASP.NET Razor VB 循环和数组
- ASP.NET MVC – 发布
- ASP.NET ViewState
- ASP.NET Style 控件
- ASP.NET Table 控件
- HTML Button
- ASP.NET HTML 控件Table 2
- ASP.NET HTML 控件 SortedList RadioButtonList 1
- ASP.NET HTML 控件 SortedList DropDownList
- ASP.NET HTML 控件 数据库链接 - 绑定一个 Repeater 控件
- C# 实例 For Each 循环
- C# 实例 Array 数组
- C# 实例 If 条件
- htmlanchor
- htmlimage
- ASP.NET Calendar CellPadding 属性
- ASP.NET Calendar VisibleDate 属性