共用方式為


HtmlInputRadioButton.Name 屬性

定義

取得或設定與 HtmlInputRadioButton 類別執行個體關聯的群組名稱。

public:
 virtual property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public override string Name { get; set; }
member this.Name : string with get, set
Public Overrides Property Name As String

屬性值

核取方塊控制項群組,HtmlInputRadioButton 類別的執行個體是這個群組的成員。

範例

下列程式碼範例示範如何使用 Name 屬性將多個 HtmlInputRadioButton 控制項分組。

<%@ Page Language="C#" 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" >
<head>
    <title>HtmlInputRadioButton Sample</title>
<script language="C#" runat="server">

      void Button1_Click(object sender, EventArgs e) 
      {

         if (Radio1.Checked == true)
            Span1.InnerHtml = "Option 1 is selected";
         else if (Radio2.Checked == true)
            Span1.InnerHtml = "Option 2 is selected";
         else if (Radio3.Checked == true)
            Span1.InnerHtml = "Option 3 is selected";
      }

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlInputRadioButton Sample</h3>

      <input type="radio" 
             id="Radio1" 
             name="Mode" 
             runat="server"/>

      Option 1<br />

      <input type="radio" 
             id="Radio2" 
             name="Mode" 
             runat="server"/>
      
      Option 2<br />

      <input type="radio" 
             id="Radio3" 
             name="Mode" 
             runat="server"/>

      Option 3

      <br />
      <span id="Span1" runat="server" />

      <br />
      <input type="button" 
             id="Button1" 
             value="Enter" 
             onserverclick="Button1_Click" 
             runat="server" />

   </form>

</body>
</html>
<%@ 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" >
<head>
    <title>HtmlInputRadioButton Sample</title>
<script language="VB" runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs)
        
        If Radio1.Checked = True Then
            Span1.InnerHtml = "Option 1 is selected"
        Else
            If Radio2.Checked = True Then
                Span1.InnerHtml = "Option 2 is selected"
            Else
                If Radio3.Checked = True Then
                    Span1.InnerHtml = "Option 3 is selected"
                End If
            End If
        End If
    End Sub 'Button1_Click

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlInputRadioButton Sample</h3>

      <input type="radio" 
             id="Radio1" 
             name="Mode" 
             runat="server"/>

      Option 1<br />

      <input type="radio" 
             id="Radio2" 
             name="Mode" 
             runat="server"/>
      
      Option 2<br />

      <input type="radio" 
             id="Radio3" 
             name="Mode" 
             runat="server"/>

      Option 3

      <br />
      <span id="Span1" runat="server" />

      <br />
      <input type="button" 
             id="Button1" 
             value="Enter" 
             onserverclick="Button1_Click" 
             runat="server" />

   </form>

</body>
</html>

備註

指定您想要包含在群組中之每個選項按鈕之 屬性的通用值 Name ,將多個 HtmlInputRadioButton 控制項分組。 當您將控制項分組 HtmlInputRadioButton 時,一次只能選取群組中的一個選項按鈕。 Checked選取控制項的 屬性會設定為 true ,而群組中所有其他選項按鈕的相同屬性則設定 false 為 。

適用於

另請參閱