繁体   English   中英

asp.net允许一次只选择一个复选框在Gridview中的行中

[英]asp.net allow to select only one checkbox at a time in row inside Gridview

在我的项目中,我正在使用在运行时生成的复选框,现在我希望用户一次仅在行中选择一个复选框,这是我的网格视图

<cc1:Grid ID="GrdWorkingCompany" runat="server" OnRowDataBound="GrdWorkingCompany_RowDataBound" EnableTypeValidation="true" CallbackMode="true" Serialize="true" ShowFooter="false" AutoGenerateColumns="false" AllowAddingRecords="true" AllowSorting="false"
Width="100%" FolderStyle="~/Styles/Grid/style_12" PageSize="18">
  <Columns>
    <cc1:Column ID="Sr_No" ReadOnly="true" DataField="SrNo" HeaderText="Sr.No." Width="50px">
    </cc1:Column>
    <cc1:Column ID="Points" ReadOnly="true" DataField="Points" HeaderText="Points" runat="server" Width="300px">
    </cc1:Column>
    <cc1:Column ID="chkPoor" ReadOnly="true" DataField="Rating1" HeaderText="Poor" Width="110px" TemplateId="tpltPoor">
    </cc1:Column>
    <cc1:Column ID="chkSatisfactory" DataField="Rating2" HeaderText="Satisfactory" ReadOnly="true" Width="110px" TemplateId="tpltSatisfactory">
    </cc1:Column>
    <cc1:Column ID="chkGood" ReadOnly="true" HeaderText="Good" DataField="Rating3" Width="110px" TemplateId="tpltGood">
    </cc1:Column>
    <cc1:Column ID="chkExcellent" HeaderText="Excellent" DataField="Rating4" Width="110px" ReadOnly="true" TemplateId="tpltEx1">
    </cc1:Column>
  </Columns>
  <TemplateSettings GroupHeaderTemplateId="GroupTemplate" />
  <Templates>
    <cc1:GridTemplate runat="server" ID="GridTemplate2">
      <Template>
        <%# Container.Column.HeaderText %>
          : <i>
                                                        <%# Container.Value %></i> (
          <%# Container.Group.PageRecordsCount %>
            <%# Container.Group.PageRecordsCount>1 ? "records" : "record" %>)
      </Template>
    </cc1:GridTemplate>
  </Templates>
  <Templates>
    <cc1:GridTemplate ID="tpltPoor">
      <Template>
        <asp:CheckBox runat="server" Checked='<%# Container.DataItem["Poor"].ToString() == "1" ? true : false %>' value="testing" CssClass="chkclass" onclick="AppoveCheckA(this)" ID="ChkID" ToolTip="<%# Container.Value %>" />
      </Template>
    </cc1:GridTemplate>
    <cc1:GridTemplate ID="tpltSatisfactory">
      <Template>
        <asp:CheckBox runat="server" Checked='<%# Container.DataItem["Satisfactory"].ToString() == "1" ? true : false %>' value="testing" CssClass="chkclass" onclick="AppoveCheckA(this)" ID="ChkID" ToolTip="<%# Container.Value %>" />
      </Template>
    </cc1:GridTemplate>
    <cc1:GridTemplate ID="tpltGood">
      <Template>
        <asp:CheckBox runat="server" Checked='<%# Container.DataItem["Good"].ToString() == "1" ? true : false %>' value="testing" CssClass="chkclass" onclick="AppoveCheckA(this)" ID="ChkID" ToolTip="<%# Container.Value %>" />
      </Template>
    </cc1:GridTemplate>
    <cc1:GridTemplate ID="tpltEx1">
      <Template>
        <asp:CheckBox runat="server" Checked='<%# Container.DataItem["Excellent"].ToString() == "1" ? true : false %>' value="testing" CssClass="chkclass" onclick="AppoveCheckA(this)" ID="ChkID" ToolTip="<%# Container.Value %>" />
      </Template>
    </cc1:GridTemplate>
  </Templates>
</cc1:Grid>

正在尝试一些代码,但没有用

我的Javacsript代码

<script type="text/javascript">
    $('input.chk').on('change', function () {
        $('input.chk').not(this).prop('checked', false);
    });
</script>

请给出任何建议。 谢谢

您的选择器有误。 您的元素都没有chk类。 应该是chkClass

 $('input.chkClass').on('change', function () { $('input.chkClass').not(this).prop('checked', false); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="checkbox" class="chkClass"> <input type="checkbox" class="chkClass"> <input type="checkbox" class="chkClass"> 

暂无
暂无

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

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