Radiobuttolist does not obey the selected Selectedvalue

Asked

Viewed 39 times

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 the selectedvalue == 2, he did not arrow, continues with the CPF checked and not the CNPJ. I tried other things besides SelectedValue, but nothing. I need to set according to what comes from the bank, ie, 1 or 2. What is wrong that does not work?

1 answer

1

You need to use the property Selectedindex for example:

if (ventBensAquisicao.TipoPessoa == 1)
    rdlCpfCnpjFornecedorBemNovo.SelectedIndex = 0;
else
   rdlCpfCnpjFornecedorBemNovo.SelectedIndex = 1;
  • You gave me this error: 'rdlCpfCnpjFornecedorBemNovo' has a Selectedindex which is invalid because it does not exist in the list of items. Parameter name: value

Browser other questions tagged

You are not signed in. Login or sign up in order to post.