views:

475

answers:

2

I have a nested datagrid seen below. When I click lnkSec, I want checkboxes of dgrIslem datagrid to be checked. How can I do it with javascript or Jquery?

<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>
A: 

Here is a sample with JQuery that I've done before. You can apply it to your grid too :

<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>
Canavar
Canavar Kardeş, bu dediğini tüm checkboxları seçmek için yaptım zaten fakat şu an istediğim biraz farklı. yukarıda yazdığım kod sonucunda şöyle bir yapı çıkıyor ortaya. Ben seç butonuna tıkladığımda o başlık altındaki alt başlıklara ait checkboxlar seçilmeli.Başlık1 SeçButonu AltBaşlık1 Checkbox AltBaşlık1 Checkbox AltBaşlık1 CheckboxBaşlık2 SeçButonu AltBaşlık2 Checkbox AltBaşlık2 Checkbox AltBaşlık2 Checkbox
mavera
A: 
$("#lnkSec").click(function(e){
  $("input:checkbox",$(this).parent().next()).attr("checked",true);
})

or

....
<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);
})
ToRrEs