2009-06-12 40 views
1

我有一個嵌套的datagrid在下面看到。當我點擊lnkSec時,我想要檢查dgrIslem datagrid的複選框。我怎樣才能用JavaScript或JQuery來做到這一點?在嵌套Datagrid中籤入相關複選框

<asp:datagrid id="dgrMenu" runat="server" Width="100%" GridLines="Horizontal" ShowHeader="False" 
    Height="8px" BorderWidth="1px" BorderColor="Gainsboro" CellPadding="0" AutoGenerateColumns="False" 
    AlternatingItemStyle-BackColor="#f5f5f5" SelectedItemStyle-BackColor="LightSteelBlue" ItemStyle-BackColor="White"> 
    <SelectedItemStyle BackColor="LightSteelBlue"></SelectedItemStyle> 
    <AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle> 
    <ItemStyle BackColor="White"></ItemStyle> 
    <HeaderStyle ForeColor="White" CssClass="ms-formlabel DataGridFixedHeader" BackColor="SteelBlue"></HeaderStyle> 
    <Columns> 
    <asp:BoundColumn Visible="False" DataField="ID_MENU"></asp:BoundColumn> 
    <asp:BoundColumn Visible="False" DataField="ID_PARENT"></asp:BoundColumn> 
    <asp:BoundColumn Visible="False" DataField="DS_PAGE"></asp:BoundColumn> 
    <asp:BoundColumn DataField="DS_MENU" HeaderText="Men&#252;"> 
     <HeaderStyle Width="200px"></HeaderStyle> 
    </asp:BoundColumn> 
    <asp:TemplateColumn> 
     <ItemTemplate> 
     <a href="#" id="lnkSec" onclick="javascript:SelectSubCheckboxes();">Seç/Kaldır</a> 
     </ItemTemplate> 
    </asp:TemplateColumn> 
    <asp:TemplateColumn HeaderText="İşlemler"> 
     <HeaderStyle Width="150px"></HeaderStyle> 
     <ItemTemplate> 
     <table id="tablo"> 
     <tr><td> 
     <asp:DataGrid id="dgrIslem" runat="server" Font-Size="7pt" Width="98%" AutoGenerateColumns="False" 
      CellPadding="0" BorderWidth="0px" Font-Names="Verdana"> 
      <HeaderStyle Font-Size="1pt"></HeaderStyle> 
      <Columns> 
      <asp:TemplateColumn> 
       <HeaderStyle HorizontalAlign="Center" Width="25px"></HeaderStyle> 
       <ItemStyle HorizontalAlign="Right"></ItemStyle> 
       <ItemTemplate> 
       <asp:CheckBox id="chkSec" runat="server"></asp:CheckBox> 
       </ItemTemplate> 
      </asp:TemplateColumn> 
      <asp:BoundColumn Visible="false" DataField="DS_ACIKLAMA"></asp:BoundColumn> 
      <asp:BoundColumn Visible="false" DataField="ID_MENU_ISLEM"></asp:BoundColumn> 
      </Columns> 
     </asp:DataGrid> 
      </td> 
     </tr> 
     </table> 
     </ItemTemplate> 
    </asp:TemplateColumn> 
    </Columns> 
</asp:datagrid> 

回答

0

以下是我之前完成的JQuery示例。你可以把它應用到您的網格太:

<asp:GridView runat="server" ID="grid"></asp:GridView> 

<input type="button" onclick="uncheckCheckBoxes()" value="UnCheck" /> 
&nbsp; 
<input type="button" onclick="checkCheckBoxes()" value="Check" /> 

<script> 
    function uncheckCheckBoxes() 
    { 
     var gridClientID = '<%= grid.ClientID %>'; 
     jQuery.each($("#" + gridClientID + " input[type='checkbox']"), function() 
     { 
      this.checked = false; 
     }); 
    } 

    function checkCheckBoxes() 
    { 
     var gridClientID = '<%= grid.ClientID %>'; 
     jQuery.each($("#" + gridClientID + " input[type='checkbox']"), function() 
     { 
      this.checked = true; 
     }); 
    } 
</script> 
0
$("#lnkSec").click(function(e){ 
    $("input:checkbox",$(this).parent().next()).attr("checked",true); 
}) 

.... 
<asp:TemplateColumn> 
    <ItemTemplate> 
    <a href="#" id="lnkSec" onclick="javascript:SelectSubCheckboxes(this);"> 
    Seç/Kaldır</a> 
    </ItemTemplate> 
</asp:TemplateColumn> 
... 

function SelectSubCheckboxes(lnkSec){ 
    $("input:checkbox",$(lnkSec).parent().next()).attr("checked",true); 
})