DropDownList クラスとは? わかりやすく解説

DropDownList クラス

ユーザードロップダウン リストから単一の項目を選択できるコントロール表します

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

<ValidationPropertyAttribute("SelectedItem")>
 _
Public Class DropDownList
    Inherits ListControl
    Implements IPostBackDataHandler
[ValidationPropertyAttribute("SelectedItem")] 
public class DropDownList : ListControl, IPostBackDataHandler
[ValidationPropertyAttribute(L"SelectedItem")] 
public ref class DropDownList : public
 ListControl, IPostBackDataHandler
/** @attribute ValidationPropertyAttribute("SelectedItem") */ 
public class DropDownList extends ListControl
 implements IPostBackDataHandler
ValidationPropertyAttribute("SelectedItem") 
public class DropDownList extends
 ListControl implements IPostBackDataHandler
解説解説

DropDownList コントロール使用して単一選択ドロップダウン リスト コントロール作成します。BorderColor、BorderStyle、BorderWidth の各プロパティ設定するDropDownList コントロール外観制御できます

DropDownList コントロール表示する項目を指定するには、各エントリに対してDropDownList コントロール開始タグ終了タグの間に ListItem オブジェクト配置します

DropDownList コントロールデータ連結サポートしてます。コントロールデータ ソースバインドするには、コントロール表示する項目を格納している System.Collections.ArrayList オブジェクトなどのデータ ソース作成しますデータ ソース作成したら、Control.DataBind メソッド使用してデータ ソースDropDownList コントロール連結します。

SelectedIndex プロパティ使用してDropDownList コントロールかユーザー選択した項目のインデックスプログラムにより確認します

ユーザー補助
TopicLocation
チュートリアル : FormView Web サーバー コントロールによる Web ページでの書式設定したデータ表示Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : GridView Web サーバー コントロール編集中のドロップダウン リスト表示Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Visual Studio でのマスター/詳細 Web ページ作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Visual Web Developer での ASP.NET マスタ ページ作成使用Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : XML データ表示する Web ページ作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディングVisual Studio での ASP .NET Web アプリケーション作成
チュートリアル : 変換による Web フォーム ページへの XML ドキュメント表示Visual Studio での ASP .NET Web アプリケーション作成
方法 : ASP.NET Web サーバー コントロールフォーカス設定するASP .NET Web アプリケーション作成
方法 : Web フォーム ページDropDownList Web サーバー コントロール追加するASP .NET Web アプリケーション作成
方法 : Web フォーム ページDropDownList Web サーバー コントロール追加する (Visual Studio)Visual Studio での ASP .NET Web アプリケーション作成
方法 : データ ソースデータリスト Web サーバー コントロール読み込むASP .NET Web アプリケーション作成
方法 : データ ソースの項目をリスト Web サーバー コントロール読み込む (Visual Studio)Visual Studio での ASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロールでの変更応答するASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロールに項目を追加するASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロールに項目を追加する (Visual Studio)Visual Studio での ASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロール選択項目を確認するASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロール選択項目を設定するASP .NET Web アプリケーション作成
方法 : リスト Web サーバー コントロール選択項目を設定する (Visual Studio)Visual Studio での ASP .NET Web アプリケーション作成
方法 : 非階層 Web Server コントロール内にサイト マップ データ表示するASP .NET Web アプリケーション作成
使用例使用例

4 つの項目が格納されている DropDownList コントロール作成する方法次のコード例示します

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

<html>
   <script runat="server" >
  
      Sub Selection_Change(sender As Object,
 e As EventArgs)

         ' Set the background color for days in the Calendar control
         ' based on the value selected by the user from the
         '  DropDownList control.
         Calendar1.DayStyle.BackColor = _
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value)

      End Sub
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> DropDownList Example </h3>

      Select a background color for days in
 the calendar.

      <br><br> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br><br>

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True"
 Value="White"> White </asp:ListItem>
                  <asp:ListItem Value="Silver">
 Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray">
 Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki">
 Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki">
 Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>
  
   </form>

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

<html>
   <script runat="server" >
  
      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the 
         // DropDownList control.
         Calendar1.DayStyle.BackColor = 
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value);

      }
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> DropDownList Example </h3>

      Select a background color for days in
 the calendar.

      <br><br> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br><br>

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True" Value="White">
 White </asp:ListItem>
                  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>
  
   </form>

</body>
</html>
 

データ バインディングにより DropDownList コントロール作成する方法次のコード例示します

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<%@ Import Namespace="System.Data"
 %>

<html>
   <script runat="server" >
  
      Sub Selection_Change(sender as Object,
 e As EventArgs)

         ' Set the background color for days in the Calendar control
 
         ' based on the value selected by the user from the
         ' DropDownList control.
         Calendar1.DayStyle.BackColor = _
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value)

      End Sub

      Sub Page_Load(sender as Object,
 e As EventArgs)
  
         ' Load data for the DropDownList control only once, when the
 
         ' page is first loaded.
         If Not IsPostBack Then

            ' Specify the data source and field names for the Text 
            ' and Value properties of the items (ListItem objects)
            ' in the DropDownList control.
            ColorList.DataSource = CreateDataSource()
            ColorList.DataTextField = "ColorTextField"
            ColorList.DataValueField = "ColorValueField"

            ' Bind the data to the control.
            ColorList.DataBind()

            ' Set the default selected item, if desired.
            ColorList.SelectedIndex = 0

         End If

      End Sub

      Function CreateDataSource() As ICollection
 
      
         ' Create a table to store data for the DropDownList control.
         Dim dt As DataTable = New
 DataTable()
         
         ' Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField",
 GetType(String)))
         dt.Columns.Add(new DataColumn("ColorValueField",
 GetType(String)))
 
         ' Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White",
 dt))
         dt.Rows.Add(CreateRow("Silver", "Silver",
 dt))
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray",
 dt))
         dt.Rows.Add(CreateRow("Khaki", "Khaki",
 dt))
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki",
 dt))
 
         ' Create a DataView from the DataTable to act as the data source
         ' for the DropDownList control.
         Dim dv As DataView = New
 DataView(dt)
         Return dv

      End Function

      Function CreateRow(Text As String,
 Value As String, dt As
 DataTable) As DataRow 

         ' Create a DataRow using the DataTable defined in the 
         ' CreateDataSource method.
         Dim dr As DataRow = dt.NewRow()
 
         ' This DataRow contains the ColorTextField and ColorValueField
 
         ' fields, as defined in the CreateDataSource method. Set the
 
         ' fields with the appropriate value. Remember that column 0
 
         ' is defined as ColorTextField, and column 1 is defined as
 
         ' ColorValueField.
         dr(0) = Text
         dr(1) = Value
 
         Return dr

      End Function
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> DropDownList Data Binding Example </h3>

      Select a background color for days in
 the calendar.

      <br><br> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br><br>

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server"/>

            </td>

         </tr>
  
   </form>

</body>
</html>
 
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<html>
   <script runat="server" >
  
      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the 
         // DropDownList control.
         Calendar1.DayStyle.BackColor = 
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value);

      }

      void Page_Load(Object sender, EventArgs e)
      {
  
         // Load data for the DropDownList control only once, when the
 
         // page is first loaded.
         if(!IsPostBack)
         {

            // Specify the data source and field names for the Text
 
            // and Value properties of the items (ListItem objects)
 
            // in the DropDownList control.
            ColorList.DataSource = CreateDataSource();
            ColorList.DataTextField = "ColorTextField";
            ColorList.DataValueField = "ColorValueField";

            // Bind the data to the control.
            ColorList.DataBind();

            // Set the default selected item, if desired.
            ColorList.SelectedIndex = 0;

         }

      }

      ICollection CreateDataSource() 
      {
      
         // Create a table to store data for the DropDownList control.
         DataTable dt = new DataTable();
         
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField",
 typeof(String)));
         dt.Columns.Add(new DataColumn("ColorValueField",
 typeof(String)));
 
         // Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White", dt));
         dt.Rows.Add(CreateRow("Silver", "Silver", dt));
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
         dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));
 
         // Create a DataView from the DataTable to act as the data
 source
         // for the DropDownList control.
         DataView dv = new DataView(dt);
         return dv;

      }

      DataRow CreateRow(String Text, String Value, DataTable dt)
      {

         // Create a DataRow using the DataTable defined in the 
         // CreateDataSource method.
         DataRow dr = dt.NewRow();
 
         // This DataRow contains the ColorTextField and ColorValueField
 
         // fields, as defined in the CreateDataSource method. Set the
 
         // fields with the appropriate value. Remember that column
 0 
         // is defined as ColorTextField, and column 1 is defined as
 
         // ColorValueField.
         dr[0] = Text;
         dr[1] = Value;
 
         return dr;

      }
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> DropDownList Data Binding Example </h3>

      Select a background color for days in
 the calendar.

      <br><br> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br><br>

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server"/>

            </td>

         </tr>
  
   </form>

</body>
</html>
 
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.BaseDataBoundControl
         System.Web.UI.WebControls.DataBoundControl
           System.Web.UI.WebControls.ListControl
            System.Web.UI.WebControls.DropDownList
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DropDownList メンバ
System.Web.UI.WebControls 名前空間
BorderColor
BorderStyle
BorderWidth
ListItem
System.Collections.ArrayList
Control.DataBind
SelectedIndex


このページでは「.NET Framework クラス ライブラリ リファレンス」からDropDownList クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDropDownList クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDropDownList クラス を検索

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

辞書ショートカット

すべての辞書の索引

「DropDownList クラス」の関連用語

DropDownList クラスのお隣キーワード
検索ランキング

   

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



DropDownList クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS