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">
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>

实例

从 DropDownList 中的一个项目取得文本
系统帮助 | 给我留言 | 收藏本站
Copyright © 2005-2008 www.cnn84.com All Rights Reserved Ver:2.0
CNN84网是公益性便民网站,是为了给大家的日常生活查询及提供最快捷的出行指南