RadioButton returning only selected status [closed]

0

Follow the code:

<asp:RadioButtonList ID="rdlCpfCnpjAvalista" CssClass="cPFCNPJRadioButtonList" runat="server" RepeatDirection="Horizontal" AutoPostBack="false">
                        <asp:ListItem Text="CPF" Value="1" Selected="True"></asp:ListItem>
                        <asp:ListItem Text="CNPJ" Value="2" Selected="True"></asp:ListItem>
                    </asp:RadioButtonList>

Any choice I make, it only brings me value = 1 . These selected = true , are my attempts.

int teste = int.Parse(rdlCpfCnpjAvalista.SelectedValue);

Test is always equal to 1.

    
asked by anonymous 17.11.2014 / 13:42

1 answer

1

As informed by @Laerte, I performed the test below and it worked perfectly.

Aspx

<form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="rdlCpfCnpjAvalista" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Text="CPF" Value="1" />                
            <asp:ListItem Text="CNPJ" Value="2" />
        </asp:RadioButtonList>
        <asp:Button ID="btnEnviar" runat="server" Text="Enviar" OnClick="btnEnviar_Click" />
    </div>
</form>

C #

protected void btnEnviar_Click(object sender, EventArgs e)
{
    // Verificando se algum valor foi selecionado.
    if (this.rdlCpfCnpjAvalista.SelectedIndex == -1) return;

    // Recuperando valor selecionado.
    var valor = this.rdlCpfCnpjAvalista.SelectedValue;
}
    
17.11.2014 / 14:17