2012-05-07 74 views
0

我使用asp.net的GridView的頭,我有兩列GridView控件與多個複選框列和選擇所有列標題

column select all employee | column select all employer 

,所以我有兩個複選框兩列,所以一旦它的點擊全選僱員應該只選擇所有僱員,同樣與僱主

但下面的代碼是選擇僱員和僱主,如果只選擇僱主。

function SelectAllCheckboxes(chk) { 
     $('#<%=gv.ClientID%>').find("input:checkbox").each(function() { 
      if (this != chk) { this.checked = chk.checked; } 
     }); 
    } 

    function SelectAllCheckboxes1(chk) { 
     $('#<%=gv.ClientID%>').find("input:checkbox").each(function() { 
      if (this != chk) { this.checked = chk.checked; } 
     }); 
    } 


<asp:CheckBox ID="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);" /> 

<asp:CheckBox ID="chkAll1" runat="server" onclick="javascript:SelectAllCheckboxes1(this);" /> 
+0

你是什麼意思?當你點擊'Select All Employers'時,Select All Employees'也會被檢查? –

+0

嗯,這是有道理的,因爲你沒有區分兩個複選框。在服務器端的「僱主」僱主複選框添加一個類然後,選擇「輸入:checkbox.employer」 – tedski

+0

我有兩列在gridview標題,如果點擊列1列1複選框應該是選擇,如果我點擊第2列然後第2列複選框應該選擇,但在我的情況下,如果我選擇第1列,那麼列1和列2複選框被選中 –

回答

1

ASP - 在你的GridView:

<asp:GridView id="gv" runat="server"> 
    <asp:TemplateField> 
     <ItemTemplate> 
      <asp:CheckBox id="cbxSelectEmployer" runat="server" CssClass="employer" /> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField> 
     <ItemTemplate> 
      <asp:CheckBox id="cbxSelectEmployee" runat="server" CssClass="employee" /> 
     </ItemTemplate> 
    </asp:TemplateField> 
</asp:GridView> 

ASP - 「全選」 複選框:

<asp:CheckBox ID="chkAll" runat="server" onclick="SelectAllCheckboxes(this, '.employee')" /> 
<asp:CheckBox ID="chkAll1" runat="server" onclick="SelectAllCheckboxes(this, '.employer')" /> 

jQuery的

function SelectAllCheckboxes(chk, selector) { 
    $('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function() { 
     $(this).prop("checked", $(chk).prop("checked")); 
    }); 
} 
+0

好吧,所以粘貼代碼,當我點擊在標題中的複選框沒有做任何事情沒有錯誤什麼都沒有 –

+0

然後我就這樣傳遞'onclick =「SelectAllCheckboxes(this,'employee')」'(取出點)然後它拋出一個錯誤在這裏 '微軟JScript運行時錯誤:拋出異常並沒有捕獲' –

+0

我得到的錯誤是在jquery.js –

相關問題