ASP.NET Model Binding, ListView & CheckBox.Checked -



ASP.NET Model Binding, ListView & CheckBox.Checked -

i using asp.net 4.5 model binding nowadays items in listview command editing.

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

when add together edititemtemplate, have checkbox , trying bind checked property model...

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

this problem starts, running page shows message of "cs0030: cannot convert type 'string' 'bool'", prompting line...

<td> <asp:checkbox id="isactive" runat="server" checked="<%#: binditem.isclientactive %>" /> </td>

what have missed? how bind value of isclientactive checked property of checkbox control? worth noting that, within model, isclientactive property defined boolean , not nullable.

my bad; checked="<%#: binditem.isclientactive %>" should have been checked="<%# binditem.isclientactive %>" (note omission of colon (:))

asp.net checkbox .net-4.5 model-binding

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -