1

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?!

4

1 回答 1

1

C# 中的布尔值用大写字母输出它们的值,所以

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

输出False,不是false。尝试在您的标记中反映这一点:

<asp:ListItem Text="Item 1" Value="False"></asp:ListItem>
<asp:ListItem Text="Item 2" Value="True"></asp:ListItem>
于 2013-07-17T14:08:20.243 回答