RadioButtoList does not obey selected SelectedValue

0

I have this Radiobutton:

<asp:RadioButtonList ID="rdlCpfCnpjFornecedorBemNovo" CssClass="cPFCNPJRadioButtonList" runat="server" RepeatDirection="Horizontal" AutoPostBack="false" RepeatLayout="Flow">
                <asp:ListItem Text="CPF&nbsp;&nbsp;&nbsp;" Value="1"></asp:ListItem>
                <asp:ListItem Text="CNPJ&nbsp;&nbsp;&nbsp;" Value="2"></asp:ListItem>
            </asp:RadioButtonList>

In the code I have this:

rdlCpfCnpjFornecedorBemNovo.SelectedValue = ventBensAquisicao.TipoPessoa.ToString();

It turns out that when selectedvalue == 2 , it does not, it continues with CPF checked and not CNPJ . I've tried other things besides SelectedValue , but nothing. I need to set according to what comes from the bank, that is, 1 or 2. What is wrong that does not work?

    
asked by anonymous 30.01.2015 / 16:15

1 answer

1

You need to use the SelectedIndex property for example:

if (ventBensAquisicao.TipoPessoa == 1)
    rdlCpfCnpjFornecedorBemNovo.SelectedIndex = 0;
else
   rdlCpfCnpjFornecedorBemNovo.SelectedIndex = 1;
    
30.01.2015 / 20:38