You must Sign In to post a response.
  • Category: ASP.NET

    GridView Checkbox in 3 columns....pls help me. most urgent.....

    i have 3 columnus with checkbox in grid view.
    if i checked in header one check box. all check box checked in this form with treeview.
    i want same row in header checked only.
    please help me.


    <asp:GridView ID="Grid1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
    BorderStyle="None" BorderWidth="1px" CellPadding="2" DataKeyNames="PageID" HorizontalAlign="Center"
    PageSize="15" Width="100%">
    <PagerSettings PageButtonCount="100" />
    <Columns>
    <asp:BoundField DataField="PageID" Visible="false" />
    <asp:BoundField DataField="PageName" HeaderText="PageName">
    <ControlStyle Font-Underline="False" />
    </asp:BoundField>
    <asp:CheckBoxField ReadOnly="true" DataField="View" HeaderText="View" ControlStyle-Font-Underline="false" />

    <asp:TemplateField>
    <AlternatingItemTemplate>
    <asp:CheckBox ID="ChkSave" runat="server" />
    </AlternatingItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="ChkSave" runat="server" />
    </ItemTemplate>
    <HeaderTemplate>
    <asp:CheckBox ID="ChkSaveH" runat="server" Text="Save" Font-Underline="true" />
    </HeaderTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <AlternatingItemTemplate>
    <asp:CheckBox ID="ChkEdit" runat="server" />
    </AlternatingItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="ChkEdit" runat="server" />
    </ItemTemplate>
    <HeaderTemplate>
    <asp:CheckBox ID="ChkEditH" runat="server" Text="Edit" Font-Underline="true" />
    </HeaderTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <AlternatingItemTemplate>
    <asp:CheckBox ID="ChkDelete" runat="server" />
    </AlternatingItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="ChkDelete" runat="server" />
    </ItemTemplate>
    <HeaderTemplate>
    <asp:CheckBox ID="ChkDeleteH" runat="server" Text="Delete" Font-Underline="true" />
    </HeaderTemplate>
    </asp:TemplateField>
    <%--<asp:CommandField ShowSelectButton="True" Visible="False" />--%>
    </Columns>
    </asp:GridView>



    Protected Sub Grid1_RowDataBound(B
  • #215598
    Using javascript you can achieve your requirement.

  • #215600
    Hai Priya,

    tell me more.

    Once you check the header checkbox Delete. all the rows of the column delete should be checked like that you want.

  • #215702


    function CheckAll()
    {
    var varTbl=document.getElementById('<%=Grid1.ClientID%>');
    var vartblRows=document.getElementById('<%=Grid1.ClientID%>').rows.length;
    var varHeader=document.getElementById('<%=Grid1.ClientID%>').rows[0].cells[0];
    var varHeaderInputs=varHeader.getElementsByTagName("INPUT");
    if(document.getElementById(varHeaderInputs[0].id).checked)
    {
    for(i=1;i<vartblRows;i++)
    {
    var tblrowchk=document.getElementById('<%=Grid1.ClientID%>').rows[i].cells[0];
    var inputs=tblrowchk.getElementsByTagName("INPUT");
    document.getElementById(inputs[0].id).checked=true;
    }
    }
    else
    {
    for(i=1;i<vartblRows;i++)
    {
    var tblrowchk=document.getElementById('<%=Grid1.ClientID%>').rows[i].cells[0];
    var inputs=tblrowchk.getElementsByTagName("INPUT");
    document.getElementById(inputs[0].id).checked=false;
    }

    }
    }

    call this function onclick of checkbox
    <asp:CheckBox ID="ChkSaveH" runat="server" Text="Save" Font-Underline="true" onclick="javascript:CheckAll()" />


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.