2013-02-17 3 views
2

ASP.NET 4.5 모델 바인딩을 사용하여 ListView 컨트롤의 항목을 편집 할 수 있습니다. 내 EditItemTemplate을 추가 할 때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> 

... 나는 확인란을하고 난 모델에 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 값을 Checkbox 컨트롤의 Checked 속성에 바인딩하려면 어떻게합니까? 모델 내에서 IsClientActive 속성이 부울로 정의되고 nullable이 아니라는 점은 주목할 가치가 있습니다.

답변

2

나쁘다; Checked="<%#: BindItem.IsClientActive %>"Checked="<%# BindItem.IsClientActive %>"이어야합니다 (콜론 (:)의 누락에 유의하십시오)