Radiobuttonlist does not accept if Selectedindx

Asked

Viewed 54 times

0

I have this Radiolist declared:

<label>Aprovar</label>
            <asp:RadioButtonList ID="rblAprovar" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                <asp:ListItem Text="&nbsp;Sim&nbsp;&nbsp;&nbsp;" Value="1" />
                <asp:ListItem Text="&nbsp;Não&nbsp;&nbsp;&nbsp;" Value="0" />
            </asp:RadioButtonList>

And I have this command in my Behind:

if(rblAprovar.SelectedIndex = -1)
  {
    vstrMensagem += "- Aprovar não informado.<br>";
  }

This is making this mistake:

Cannot implicitly Convert 'int' to 'bool'

I have other Radiobuttonlist with the same if that does not give this error and that they are being programmed in the same way. The question is: What could be wrong with that statement? In my opinion nothing.

  • 1

    Missed the ==... if(rblAprovar.SelectedIndex == -1)

1 answer

3


What could be wrong with that statement? In my opinion nothing. @pnet

In your if you are assigning a value to Selectedindex =, you must use == for boolean checks.

if(rblAprovar.SelectedIndex == -1)
  {
    vstrMensagem += "- Aprovar não informado.<br>";
  }
  • 1

    You’re right, the pressure is great and I didn’t even realize it. What a shitty post. A little attention and care as every programmer should have and this would be avoided. We sometimes sin on minimal things. I apologize to everyone. The fact that I’m under a lot of pressure, this post should be unnecessary.

  • Calm, mate, you only live once @pnet

Browser other questions tagged

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