2
我正在使用ASP.NET 4.5模型绑定在编辑时在ListView控件中呈现项目。ASP.NET模型绑定,ListView和CheckBox.Checked
<asp:ListView ID="Results" runat="server" SelectMethod="SelectClientStatus" DataKeyNames="ID" ItemPlaceholderID="itemPlaceHolder" ItemType="ClientStatus" OnItemCommand="Results_ItemCommand" InsertItemPosition="LastItem" UpdateMethod="UpdateClientStatus" InsertMethod="InsertClientStatus">
<LayoutTemplate>
<table>
<tr>
<th runat="server">
<asp:LinkButton ID="SortByDescription" runat="server" ClientIDMode="Static" CommandName="Sort" CommandArgument="Description" Text="Description" />
</th>
<th>Active</th>
<th></th>
</tr>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</table>
<agp:PagerControl runat="server" ID="PagerControl" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#: Item.Description%>
</td>
<td>
<%#: Item.IsClientActive %>
</td>
<td>
<asp:LinkButton ID="Edit" runat="server" ClientIDMode="Static" CommandName="Edit" CommandArgument="<%#: Item.ID %>" Text="Edit" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
当我加我EditItemTemplate里,我有一个复选框,我想Checked属性绑定到模型...
<EditItemTemplate>
<tr>
<td>
<asp:TextBox ID="Description" runat="server" Text="<%#: BindItem.Description%>" />
</td>
<td>
<asp:CheckBox ID="IsActive" runat="server" Checked="<%#: BindItem.IsClientActive %>" />
</td>
<td>
<asp:LinkButton ID="Update" runat="server" ClientIDMode="Static"
CommandName="Update" CommandArgument="<%#: Item.ID %>"
Text="Update" />
<asp:LinkButton ID="Cancel" runat="server" ClientIDMode="Static"
CommandName="Cancel" CommandArgument="<%#: Item.ID %>"
Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
这就是问题的开始,现在正在运行的页面显示的消息“CS0030:无法将类型‘字符串’到‘布尔’”,用线提示...
<td>
<asp:CheckBox ID="IsActive" runat="server" Checked="<%#: BindItem.IsClientActive %>" />
</td>
有什么我错过了?如何将IsClientActive的值绑定到复选框控件的Checked属性?值得注意的是,在模型中,IsClientActive属性被定义为一个布尔值并且不可为空。