2016-05-27 84 views
0

在我的项目我使用它在运行时产生的复选框现在我想的是用户在行 一次选择只有一个复选框,这里是我的GridViewasp.net允许一次行只选择一个复选框内的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> 

请给出任何建议。 谢谢

+0

不应该说是'输入:checkbox',不'input.chk'? – Crowcoder

+0

我认为你正在寻找单选按钮控件而不是复选框,如果它们必须是互斥的。 – vittore

+0

是的,我们希望单选按钮具有相同的功能,但我们不想单选按钮 – ash060

回答

1

您的选择是错误的。没有一个元素的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">

+0

它不能正常工作,面临同样的问题 – ash060

+0

您是否实际上正在加载jQuery?控制台中是否有错误?如果你看看生成的HTML是否有你期望的类? – Turnip

+0

没有我没有得到控制台中的y错误 – ash060

相关问题