HtmlSelect.SelectedIndex プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlSelect.SelectedIndex プロパティの意味・解説 

HtmlSelect.SelectedIndex プロパティ

HtmlSelect コントロール選択された項目の序数インデックス取得または設定します

名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Overridable Property
 SelectedIndex As Integer
Dim instance As HtmlSelect
Dim value As Integer

value = instance.SelectedIndex

instance.SelectedIndex = value
public virtual int SelectedIndex { get;
 set; }
public:
virtual property int SelectedIndex {
    int get ();
    void set (int value);
}
/** @property */
public int get_SelectedIndex ()

/** @property */
public void set_SelectedIndex (int
 value)
public function get SelectedIndex
 () : int

public function set SelectedIndex
 (value : int)

プロパティ
HtmlSelect コントロール選択された項目の序数インデックス。値が -1 である場合は項目が選択されていないことを示します

解説解説

SelectedIndex プロパティ通常単一選択 HtmlSelect コントロール選択された項目のインデックス確認するために使用されます。このインデックス使用して Items コレクションから項目を取得できます

Multiple プロパティが、複数の項目を同時に選択できることを示す true設定されている場合SelectedIndex プロパティには最初に選択した項目のインデックス格納されます。複数同時選択ができる HtmlSelect コントロール選択された項目を確認するには、Items コレクション反復処理して各項目の ListItem.Selected プロパティテストします

注意に関するメモ注意

項目を選択しなくてもかまいません。項目を選択しなかった場合SelectedIndex プロパティ-1 の値を格納します。これは通常最初にページ読み込まれ既定で項目が選択されていない場合発生しますItems コレクションの項目を参照する前にこの値をテストするコード作成しますそうしない場合インデックスコレクション範囲外場合例外スローさます。

既定では、HtmlSelect コントロールドロップダウン リスト ボックスとして表示されます。Multiple プロパティtrue設定して複数の項目を選択できるようにした場合、または Size プロパティ1超える値に設定して、高さを 1 行の高さよりも高く指定した場合、このコントロールリスト ボックスとして表示されます。ドロップダウン リスト ボックス表示される場合は、常に 1 つの項目が選択されています。リスト ボックス表示され場合は、SelectedIndex プロパティ-1設定することによって、すべての項目の選択プログラム解除できます

使用例使用例

SelectedIndex プロパティ使用してHtmlSelect コントロール選択された項目のインデックス確認する方法次のコード例示します。このインデックス使用して Items コレクションから選択された項目を取得します

<%@ Page Language="VB" AutoEventWireup="True"
 %>

<html>

<head>

   <script runat="server">

      Sub Button_Click (sender As Object,
 e As EventArgs)
        
         Label1.Text = "You selected the item with index number
 " & _
                       Select1.SelectedIndex.ToString() & _
                       " and contains the value "
 & _
                       Select1.Value & "."

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select items from the list: <br><br>

      <select id="Select1" 
              Multiple="False"
              runat="server">

         <option value="Text for Item 1" Selected="True">
 Item 1 </option>
         <option value="Text for Item 2"> Item
 2 </option>
         <option value="Text for Item 3"> Item
 3 </option>
         <option value="Text for Item 4"> Item
 4 </option>
         <option value="Text for Item 5"> Item
 5 </option>
         <option value="Text for Item 6"> Item
 6 </option>

      </select>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      void Button_Click (Object sender, EventArgs e)
      {
        
         Label1.Text = "You selected the item with index number " + 
                       Select1.SelectedIndex.ToString() + 
                       " and contains the value " +
                       Select1.Value + ".";

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select items from the list: <br><br>

      <select id="Select1" 
              Multiple="False"
              runat="server">

         <option value="Text for Item 1" Selected="True">
 Item 1 </option>
         <option value="Text for Item 2"> Item
 2 </option>
         <option value="Text for Item 3"> Item
 3 </option>
         <option value="Text for Item 4"> Item
 4 </option>
         <option value="Text for Item 5"> Item
 5 </option>
         <option value="Text for Item 6"> Item
 6 </option>

      </select>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      function Button_Click (sender : Object, e: EventArgs) :
  void
      {
        
         Label1.Text = "You selected the item with index number " + 
                       Select1.SelectedIndex.ToString() + 
                       " and contains the value " +
                       Select1.Value + ".";

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select items from the list: <br><br>

      <select id="Select1" 
              Multiple="False"
              runat="server">

         <option value="Text for Item 1" Selected="True">
 Item 1 </option>
         <option value="Text for Item 2"> Item
 2 </option>
         <option value="Text for Item 3"> Item
 3 </option>
         <option value="Text for Item 4"> Item
 4 </option>
         <option value="Text for Item 5"> Item
 5 </option>
         <option value="Text for Item 6"> Item
 6 </option>

      </select>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlSelect クラス
HtmlSelect メンバ
System.Web.UI.HtmlControls 名前空間
HtmlSelect.Items プロパティ
ListItem.Selected
HtmlSelect.Multiple プロパティ
Size
その他の技術情報
HTML サーバー コントロール



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HtmlSelect.SelectedIndex プロパティ」の関連用語

HtmlSelect.SelectedIndex プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlSelect.SelectedIndex プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS