【问题标题】:Listview with checkboxes Asp.net带有复选框的列表视图 Asp.net
【发布时间】:2020-12-01 19:11:04
【问题描述】:

我有一个列表视图,里面有标签和复选框。如何将复选框的选择模式限制为单个。我想一次只选择一个复选框。

这是我的代码 .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>


【问题讨论】:

    标签: c# asp.net listview checkbox


    【解决方案1】:
    **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. 
                }
           });
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2018-02-14
      • 2014-04-11
      相关资源
      最近更新 更多