Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
    </script>
    <script type="text/javascript">

        $(function () {

            //Column index value of price field (Column index start from 1)
            var columnIndexValue = 2;

            var checked = $('input:checkbox').click(function (e) {

                var total = 0;
                $("tr:has(:checkbox:checked) td:nth-child(" + columnIndexValue + ")").each(function () {
                    total += parseInt($(this).text());
                });

                $('#txt').val(total.toFixed());


            });

        });


    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
            GridLines="None" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
            CellSpacing="1" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
            <columns>
                <asp:TemplateField>
                    <itemtemplate>
                        <asp:CheckBox ID="Check" runat="server" />
                        <%--<input type="checkbox"  id="chk"  runat="server" />--%>
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="Emp Salary">
                    <itemtemplate>
                        <%#Eval("EmpSalary") %>
                    </itemtemplate>
                
            </columns>
            <footerstyle backcolor="#C6C3C6" forecolor="Black" />
            <rowstyle backcolor="#DEDFDE" forecolor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <pagerstyle backcolor="#C6C3C6" forecolor="Black" horizontalalign="Right" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        
        <p id="tot">
        </p>
    </div>
    <br />
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Select All
     |
    <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Deselct All
     |
    <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">Delete
    <br />
    <asp:Label ID="lbl" runat="server">
    <asp:TextBox ID="txt" runat="server" MaxLength="50">
    <br />
    <br />
    <br />
    <table>
        <tr>
            <td id="tttt">
            </td>
        </tr>
    </table>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="height: 26px"
        Text="Button" />
    </form>
</body>
</html>



can any one help me, i want the same operation in C# code. please help me.
Actually its working fine,but when i try to keep grid in a table.its not working
Posted
Updated 13-Oct-11 0:05am
v2

1 solution

try accessing in this form, as it works for me
C#
var headerCheckbox = $('#GridView1 > tbody > tr > th > input:checkbox');

      headerCheckbox.click(function() {
         var headerChecked = $(this).attr('checked');
         var rowCheckboxes = $('#GridView1 > tbody > tr > td > input:checkbox');
         rowCheckboxes.attr('checked', headerChecked);
      });
 
Share this answer
 
Comments
Anuja Pawar Indore 13-Oct-11 6:21am    
R u referring this
http://www.dotnetcurry.com/ShowArticle.aspx?ID=662
yerrojumeher 13-Oct-11 6:44am    
thanks
pawar
Anuja Pawar Indore 13-Oct-11 7:21am    
Welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900