次の方法で共有


HtmlInputCheckBox.Checked プロパティ

HtmlInputCheckBox が選択されているかどうかを示す値を取得または設定します。

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

構文

'宣言
<TypeConverterAttribute(GetType(MinimizableAttributeTypeConverter))> _
Public Property Checked As Boolean
'使用
Dim instance As HtmlInputCheckBox
Dim value As Boolean

value = instance.Checked

instance.Checked = value
[TypeConverterAttribute(typeof(MinimizableAttributeTypeConverter))] 
public bool Checked { get; set; }
[TypeConverterAttribute(typeof(MinimizableAttributeTypeConverter))] 
public:
property bool Checked {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Checked ()

/** @property */
public void set_Checked (boolean value)
public function get Checked () : boolean

public function set Checked (value : boolean)
適用できません。

プロパティ値

HtmlInputCheckBox コントロールが選択されている場合は true。それ以外の場合は false

解説

このプロパティを使用して、HtmlInputCheckBox コントロールが選択されているかどうかを確認します。このプロパティは、HtmlInputCheckBox コントロールの状態をプログラムにより設定するときにも使用できます。

使用例

HtmlInputCheckBox コントロールのグループからユーザーがコントロールを選択した場合の応答を次のコード例に示します。

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <script language="VB" runat="server">
       Sub SubmitBtn_Click (Source As Object, ByVal E as EventArgs)
           If (Basketball.Checked = true) Then 
               ' You like basketball
           End If
 
           If (Football.Checked = true) Then
               ' You like football
           End If
 
           If (Soccer.Checked = true) Then
               ' You like soccer
           End If
       End Sub
    </script>
  
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
       <form id="form1" method="post" runat="server">
         Enter Interests:  
         <input id="Basketball" checked="checked" type="checkbox" runat="server" /> Basketball
         <input id="Football" type="checkbox" runat="server" /> Football
         <input id="Soccer" type="checkbox" runat="server" /> Soccer
                 
         <input type="button" value="Enter" onserverclick="SubmitBtn_Click" runat="server" />
        </form>
    </body>
 </html>
   
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  >
  <script language="C#" runat="server">

    protected void SubmitBtn_Click(object sender, EventArgs e)
    {
      if (Basketball.Checked)
      {
        // You like basketball
      }
      
      if (Football.Checked)
      {
        // You like football
      }
      
      if (Soccer.Checked)
      {
        // You like soccer
      }
    
    }
</script>
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
       <form id="Form1" method="post" runat="server">
         Enter Interests:  
         <input id="Basketball" checked="checked" type="checkbox" runat="server" /> Basketball
         <input id="Football" type="checkbox" runat="server" /> Football
         <input id="Soccer" type="checkbox" runat="server" /> Soccer
                 
         <input id="Button1" type="button" value="Enter" onserverclick="SubmitBtn_Click" runat="server" />
        </form>
    </body>
 </html>
   
<%@ Page Language="JScript" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <script language="JSCRIPT" runat="server">
       function SubmitBtn_Click (source : Object, e : EventArgs){
           if(Basketball.Checked == true){
               // You like basketball
           }
 
           if(Football.Checked == true){
               // You like football
           }
 
           if(Soccer.Checked == true){
               // You like soccer
           }
       }
    </script>
  
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
       <form id="form1" method="post" runat="server">
         Enter Interests:  
         <input id="Basketball" checked="checked" type="checkbox" runat="server" /> Basketball
         <input id="Football" type="checkbox" runat="server" /> Football
         <input id="Soccer" type="checkbox" runat="server" /> Soccer
                 
         <input type="button" value="Enter" onserverclick="SubmitBtn_Click" runat="server" />
        </form>
    </body>
 </html>
   

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HtmlInputCheckBox クラス
HtmlInputCheckBox メンバ
System.Web.UI.HtmlControls 名前空間

その他の技術情報

HTML サーバー コントロール