Share via


RadioButtonList controle de servidor Web Declarative sintaxe

Cria um agrupar de botões de opção. Esse controle suporta ligação a uma fonte de dados.

<asp:RadioButtonList
    AccessKey="string"
    AppendDataBoundItems="True|False"
    AutoPostBack="True|False"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CausesValidation="True|False"
    CellPadding="integer"
    CellSpacing="integer"
    CssClass="string"
    DataMember="string"
    DataSource="string"
    DataSourceID="string"
    DataTextField="string"
    DataTextFormatString="string"
    DataValueField="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnSelectedIndexChanged="SelectedIndexChanged event handler"
    OnTextChanged="TextChanged event handler"
    OnUnload="Unload event handler"
    RepeatColumns="integer"
    RepeatDirection="Horizontal|Vertical"
    RepeatLayout="Table|Flow"
    runat="server"
    SelectedIndex="integer"
    SelectedValue="string"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    TextAlign="Left|Right"
    ToolTip="string"
    ValidationGroup="string"
    Visible="True|False"
    Width="size"
>
            <asp:ListItem
                Enabled="True|False"
                Selected="True|False"
                Text="string"
                Value="string"
            />
</asp:RadioButtonList>

Comentários

The RadioButtonList o controle permite que você criar um agrupar de botões de opção de seleção simples que pode ser gerado dinamicamente por ligação a uma fonte de dados. Para especificar os itens que você deseja que apareça no RadioButtonList controlar, coloque um ListItem elemento para cada entrada entre as Rótulos de abertura e fechamento das RadioButtonList controle.

ObservaçãoObservação:

Você também pode usar o Controle RadioButton The RadioButtonList o controle é mais fácil para a criação de um conjunto de botões de opção usando vinculação de dados, enquanto um indivíduo RadioButton controle oferece a você maior controle sobre o layout.

The RadioButtonList controle também suporta vinculação de dados. Para BIND o controle a uma fonte de dados, primeiro crie uma fonte de dados, sistema autônomo um ArrayList objeto, que contém sistema autônomo itens a serem exibidos no controle. Em seguida, use o DataBind método para BIND a fonte de dados para o RadioButtonList controle. Use o DataTextField e DataValueField propriedades para especificar qual campo na fonte de dados para BIND a Text e Value Propriedades, respectivamente, de cada item da lista no controle. The RadioButtonList Agora o controle exibirá as informações da fonte de dados.

Para determinar os itens selecionados no RadioButtonList controlar, fazer uma iteração através da Items coleta e teste a Selected propriedade de cada item na coleção.

Você pode especificar o renderização da lista com o RepeatLayout e RepeatDirection Propriedades. If RepeatLayout é conjunto para Table (a padrão conjunto seletiva), a lista será processada dentro de uma tabela. Se for conjunto para Flow, a lista será processada sem nenhuma estrutura tabular. Por padrão, RepeatDirection é conjunto para Vertical. configuração Esta propriedade como Horizontal irá processar a lista horizontalmente.

Aviso

O texto não é codificado antes que seja exibido em HTML a Controle RadioButtonList Isso torna possível incorporar o script nas Rótulos HTML no texto. Se os valores para o controle provenientes da entrada do usuário, certifique-se de validar os valores para ajudar a evitar vulnerabilidades de segurança.

Para obter informações detalhadas sobre o RadioButtonList Propriedades e eventos de controle de servidor de Web, consulte o RadioButtonList documentação da classe.

Exemplo

O exemplo a seguir demonstra como usar um RadioButtonList controle para exibir um conjunto de opções mutuamente exclusivas para o usuário.

<%@ 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>RadioButtonList Example</title>
<script language="VB" runat="server">

    Sub Button1_Click(Source As Object, e As EventArgs)
        If RadioButtonList1.SelectedIndex > - 1 Then
            Label1.Text = "You selected: " & RadioButtonList1.SelectedItem.Text
        End If
    End Sub

    Sub chkLayout_CheckedChanged(sender As Object, e As EventArgs)        
        If chkLayout.Checked = True Then
            RadioButtonList1.RepeatLayout = RepeatLayout.Table
        Else
            RadioButtonList1.RepeatLayout = RepeatLayout.Flow
        End If
    End Sub

    Sub chkDirection_CheckedChanged(sender As Object, e As EventArgs)        
        If chkDirection.Checked = True Then
            RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal
        Else
            RadioButtonList1.RepeatDirection = RepeatDirection.Vertical
        End If
    End Sub

     </script>

 </head>
 <body>

     <h3>RadioButtonList Example</h3>

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

         <asp:RadioButtonList id="RadioButtonList1" runat="server">
            <asp:ListItem>Item 1</asp:ListItem>
            <asp:ListItem>Item 2</asp:ListItem>
            <asp:ListItem>Item 3</asp:ListItem>
            <asp:ListItem>Item 4</asp:ListItem>
            <asp:ListItem>Item 5</asp:ListItem>
            <asp:ListItem>Item 6</asp:ListItem>
         </asp:RadioButtonList>

         <br />

         <asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />

         <br />

         <asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />

         <br />

         <asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>

         <br />

         <asp:Label id="Label1" font-names="Verdana" font-size="8pt" runat="server"/>

     </form>

 </body>
 </html>

<%@ 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>RadioButtonList Example</title>
<script language="C#" runat="server">

        void Button1_Click(object Source, EventArgs e) 
        {
           if (RadioButtonList1.SelectedIndex > -1) 
           {  
              Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text;
           }
        }

        void chkLayout_CheckedChanged(Object sender, EventArgs e) 
        {

           if (chkLayout.Checked == true) 
           {
              RadioButtonList1.RepeatLayout = RepeatLayout.Table;
           }
           else 
           {
              RadioButtonList1.RepeatLayout = RepeatLayout.Flow;
           }     
        }

        void chkDirection_CheckedChanged(Object sender, EventArgs e) 
        {

           if (chkDirection.Checked == true) 
           {
              RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
           }
           else 
           {
              RadioButtonList1.RepeatDirection = RepeatDirection.Vertical;
           }  
        }

     </script>

 </head>
 <body>

     <h3>RadioButtonList Example</h3>

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

         <asp:RadioButtonList id="RadioButtonList1" runat="server">
            <asp:ListItem>Item 1</asp:ListItem>
            <asp:ListItem>Item 2</asp:ListItem>
            <asp:ListItem>Item 3</asp:ListItem>
            <asp:ListItem>Item 4</asp:ListItem>
            <asp:ListItem>Item 5</asp:ListItem>
            <asp:ListItem>Item 6</asp:ListItem>
         </asp:RadioButtonList>

         <br />

         <asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />

         <br />

         <asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />

         <br />

         <asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>

         <br />

         <asp:Label id="Label1" font-names="Verdana" font-size="8pt" 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" >
 <head>
    <title>RadioButtonList Example</title>
<script language="JScript" runat="server">

        function Button1_Click(Source : System.Object, e : EventArgs) 
        {
           if (RadioButtonList1.SelectedIndex > -1) 
           {  
              Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text;
           }
        }

        function chkLayout_CheckedChanged(sender : System.Object, e : EventArgs) 
        {

           if (chkLayout.Checked == true) 
           {
              RadioButtonList1.RepeatLayout = RepeatLayout.Table;
           }
           else 
           {
              RadioButtonList1.RepeatLayout = RepeatLayout.Flow;
           }     
        }

        function chkDirection_CheckedChanged(sender : System.Object, e : EventArgs) 
        {

           if (chkDirection.Checked == true) 
           {
              RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
           }
           else 
           {
              RadioButtonList1.RepeatDirection = RepeatDirection.Vertical;
           }  
        }

     </script>

 </head>
 <body>

     <h3>RadioButtonList Example</h3>

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

         <asp:RadioButtonList id="RadioButtonList1" runat="server">
            <asp:ListItem>Item 1</asp:ListItem>
            <asp:ListItem>Item 2</asp:ListItem>
            <asp:ListItem>Item 3</asp:ListItem>
            <asp:ListItem>Item 4</asp:ListItem>
            <asp:ListItem>Item 5</asp:ListItem>
            <asp:ListItem>Item 6</asp:ListItem>
         </asp:RadioButtonList>

         <br />

         <asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />

         <br />

         <asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />

         <br />

         <asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>

         <br />

         <asp:Label id="Label1" font-name="Verdana" font-size="8pt" runat="server"/>

     </form>

 </body>
 </html>

Consulte também

Referência

RadioButtonList

Outros recursos

controle de servidor Web sintaxe