开发者

Selecting items of a Listview using checkboxes in ASP .NET

I am trying to use checkboxes to select the items in a Listview. I have added a checkbox control in the , and they are displayed properly.

The problem is that Checked property never changes when I click on them. Why does this happen? And is there a workaround?

Here is the code:

<asp:ListView ID="ListView1" runat="server" 
    onitemcommand="ListView1_ItemCommand" 
    onitemdatabound="ListView1_ItemDataBound">
    <LayoutTemplate>
        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </LayoutTemplate>
    <ItemTemplate>
        <asp:CheckBox ID="CheckBoxSelect" runat="server" OnCheckedChanged="CheckBoxSelect_checkchanged"/>            
        <asp:LinkButton ID="LinkButtonOpen" CommandArgument='<%#Eval("MessageID") %>' runat="server">            
            &nbsp; &nbsp; &nbsp;
            <asp:Label ID="Label1" Text="[]" runat="server"/>
            &nbsp; &nbsp; &nbsp;
            <%#Eval("FirstName" )%>&nbsp;<%#Eval("LastName")%>
            &nbsp; &nbsp; &nbsp;
            <%#Eval("Subject") %>
            &nbsp; &nbsp; &nbsp;
            <%#Eval("Timestamp") %>
            <asp:HiddenField runat="server" ID开发者_运维知识库="ReadStatus" Value='<%#Eval("IsRead") %>' />
        </asp:LinkButton>
    </ItemTemplate>
</asp:ListView>


I think you are missing the AutoPostBack="true"

<asp:CheckBox ID="CheckBoxSelect" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBoxSelect_checkchanged"/>       


The problem was that I was binding the ListView during page load. When that happened, the checkboxes would get cleared, and I got the Checked property as False in all subsequent functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜