2013-07-17 30 views
1

我有一個包含2個listitems的RadioButtonList。這兩個列表項的值是true和false。MVP RadioButtonList SelectValue無效

我有一個叫做Daily的布爾值。每天被設置爲「假」

下面的代碼片段:

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

問題上運行我得到的follwing錯誤: 「pfRadioButtonList」具有的SelectedValue,因爲它不存在,這是無效的項目列表。

任何人都請提出建議?!

回答

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> 
+0

謝謝..我應該已經發現.. .. – Fiona