简体   繁体   English

带有复选框的列表视图 Asp.net

[英]Listview with checkboxes Asp.net

I have a Listview with labels and checkboxes inside.How to restrict the selection mode of the checkbox to single.I want to select only one checkbox at a time.我有一个带有标签和复选框的列表视图。如何将复选框的选择模式限制为单个。我想一次只 select 一个复选框。

Here is my code.aspx page这是我的 code.aspx 页面


   <asp:ListView runat="server" ID="ListviewCategories">
                                        <LayoutTemplate>
                                            <table runat="server" id="table1">
                                                <tr runat="server" id="itemPlaceholder">
                                                </tr>
                                            </table>
                                        </LayoutTemplate>
                                        <ItemTemplate>
                                            <tr id="Tr1" runat="server">
                                                <td id="Td2" runat="server">
                                                    <asp:Label runat="server" ID="lblCategoryId" Text='<%#Eval("CategoryId") %>' Visible="false"></asp:Label>
                                                    <asp:Label ID="CategoryName" runat="server" Text='<%#Eval("CategoryName") %>' />
                                                </td>
                                                <td id="Td3" runat="server">
                                                    <asp:CheckBox ID="ChkCategory" runat="server" OnCheckedChanged="ChkCategory_CheckedChanged" AutoPostBack="true" />
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                    </asp:ListView>


**jQuery**

    $(document).ready(function(){
       $("input[type=checkbox]").click(function(eventData){
            var checked = $(eventData.currentTarget).prop("checked");
            if(checked === "checked"){
                 $("input[type=checkbox]").prop("checked", false);//uncheck everything.
                 $(eventData.currentTarget).prop("checked", "checked");//recheck this one. 
            }
       });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM