CheckBoxList コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > CheckBoxList コンストラクタの意味・解説 

CheckBoxList コンストラクタ

CheckBoxList クラス新しインスタンス初期化します。

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

public CheckBoxList ()
public:
CheckBoxList ()
public CheckBoxList ()
public function CheckBoxList ()
解説解説
使用例使用例

CheckBoxList コントロール新しインスタンス作成および初期化する方法コード例次に示します

メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

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

<html>

<head>

   <script runat="server">

      Sub Check_Clicked(sender As Object,
 e As EventArgs) 

         ' Retrieve the CheckBoxList control from the Controls collection
         ' of the PlaceHolder control.
         Dim checklist As CheckBoxList = _
             CType(Place.FindControl("checkboxlist1"),
 CheckBoxList)

         ' Make sure a control was found.
         If Not checklist Is
 Nothing

            Message.Text = "Selected Item(s):<br><br>"

            ' Iterate through the Items collection of CheckBoxList 
            ' control and display the selected items.
            Dim i As Integer

            For i=0 To checklist.Items.Count
 - 1

               If checklist.Items(i).Selected Then

                  Message.Text &= checklist.Items(i).Text & "<br>"

               End If

            Next i

         Else

            ' Display an error message.
            Message.Text = "Unable to find CheckBoxList control."

         End If

      End Sub

      Sub Page_Load(sender As Object,
 e As EventArgs)

         ' Create a new CheckBoxList control.
         Dim checklist As CheckBoxList = New
 CheckBoxList()

         ' Set the properties of the control.
         checklist.ID = "checkboxlist1"
         checklist.AutoPostBack = True
         checklist.CellPadding = 5
         checklist.CellSpacing = 5
         checklist.RepeatColumns = 2
         checklist.RepeatDirection = RepeatDirection.Vertical
         checklist.RepeatLayout = RepeatLayout.Flow
         checklist.TextAlign = TextAlign.Right

         ' Populate the CheckBoxList control.
         checklist.Items.Add(New ListItem("Item
 1"))
         checklist.Items.Add(New ListItem("Item
 2"))
         checklist.Items.Add(New ListItem("Item
 3"))
         checklist.Items.Add(New ListItem("Item
 4"))
         checklist.Items.Add(New ListItem("Item
 5"))
         checklist.Items.Add(New ListItem("Item
 6"))

         ' Manually register the event-handling method for the 
         ' SelectedIndexChanged event.
         AddHandler checklist.SelectedIndexChanged, AddressOf
 Check_Clicked

         ' Add the control to the Controls collection of the 
         ' PlaceHolder control.
         Place.Controls.Add(checklist)

      End Sub

   </script>
 
</head>

<body>
   
   <form runat="server">
 
      <h3> CheckBoxList Constructor Example </h3>

      Select items from the CheckBoxList.

      <br><br>

      <asp:PlaceHolder id="Place" runat="server"/>
 
      <br><br>

      <asp:label id="Message" runat="server"/>
             
   </form>
          
</body>

</html>

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

<html>

<head>

   <script runat="server">

      void Check_Clicked(Object sender, EventArgs e) 
      {

         // Retrieve the CheckBoxList control from the Controls collection
         // of the PlaceHolder control.
         CheckBoxList checklist = 
             (CheckBoxList)Place.FindControl("checkboxlist1");

         // Make sure a control was found.
         if(checklist != null)
         { 

            Message.Text = "Selected Item(s):<br><br>";

            // Iterate through the Items collection of the CheckBoxList
 
            // control and display the selected items.
            for (int i=0; i<checklist.Items.Count;
 i++)
            {

               if (checklist.Items[i].Selected)
               {

                  Message.Text += checklist.Items[i].Text + "<br>";

               }

            }

         }

         else
         {

            // Display an error message.
            Message.Text = "Unable to find CheckBoxList control.";

         }

      }

      void Page_Load(Object sender, EventArgs e)
      {

         // Create a new CheckBoxList control.
         CheckBoxList checklist = new CheckBoxList();

         // Set the properties of the control.
         checklist.ID = "checkboxlist1";
         checklist.AutoPostBack = true;
         checklist.CellPadding = 5;
         checklist.CellSpacing = 5;
         checklist.RepeatColumns = 2;
         checklist.RepeatDirection = RepeatDirection.Vertical;
         checklist.RepeatLayout = RepeatLayout.Flow;
         checklist.TextAlign = TextAlign.Right;

         // Populate the CheckBoxList control.
         checklist.Items.Add(new ListItem("Item 1"));
         checklist.Items.Add(new ListItem("Item 2"));
         checklist.Items.Add(new ListItem("Item 3"));
         checklist.Items.Add(new ListItem("Item 4"));
         checklist.Items.Add(new ListItem("Item 5"));
         checklist.Items.Add(new ListItem("Item 6"));

         // Manually register the event-handling method for the 
         // SelectedIndexChanged event.
         checklist.SelectedIndexChanged += new EventHandler(this.Check_Clicked);

         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Add(checklist);

      }

   </script>
 
</head>

<body>
   
   <form runat="server">
 
      <h3> CheckBoxList Constructor Example </h3>

      Select items from the CheckBoxList.

      <br><br>

      <asp:PlaceHolder id="Place" runat="server"/>
 
      <br><br>

      <asp:label id="Message" runat="server"/>
             
   </form>
          
</body>

</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「CheckBoxList コンストラクタ」の関連用語

CheckBoxList コンストラクタのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS