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 /> Name is: <asp:Label id="lbl" Runat="Server"/> </form>
インスタンス
- DropDownList の中のいずれかのアイテムからテキストを取得する