Question

I have a RadioButtonList with 2 listitems. The value of the two list items is true and false.

I've a boolean value called Daily. Daily is set to 'false'

Here's the code snippet:

 <asp:RadioButtonList runat="server" ID="pfRadioButtonList" SelectedValue="<%# Model.Daily.ToString() %>" AutoPostBack="True" OnSelectedIndexChanged="PFRadioButtonList_OnSelectedIndexChanged">
       <asp:ListItem Text="Item 1" Value="false"></asp:ListItem>
       <asp:ListItem Text="Item 2" Value="true"></asp:ListItem>
  </asp:RadioButtonList>

The problem is on running I get the follwing error: 'pfRadioButtonList' has a selectedvalue which is invalid because it does not exist in the list of items.

Any suggestions anyone please?!

Was it helpful?

Solution

Booleans in C# output their values with capital letters, so

bool f = false;
Console.Write(f.ToString());

outputs False, not false. Try reflecting that in your markup:

<asp:ListItem Text="Item 1" Value="False"></asp:ListItem>
<asp:ListItem Text="Item 2" Value="True"></asp:ListItem>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top