.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Function to Check/Uncheck all gridview Checkbox According to Parent Checkbox with javascript

Posted By:Rajshree       Posted Date: October 22, 2010    Points: 15    Category: Javascript    URL: http://www.dotnetspark.com  

Here is Function to check/uncheck all gridview Checkbox According to Parent Checkbox.

javascript code:

 function checkuncheck(parentid)
            //get reference of GridView control
            var grid = document.getElementById("<%= gvPayments.ClientID %>");
            //variable to contain the cell of the grid
            var cell;
            if (grid.rows.length > 0)
                //loop starts from 1. rows[0] points to the header.
                for (i=1; i                {
                    //get the reference of first column
                    cell = grid.rows[i].cells[0];
                    //loop according to the number of childNodes in the cell
                    for (j=0; j                    {          
                        //if childNode type is CheckBox                
                        if (cell.childNodes[j].type =="checkbox")
                        //assign the status of the Select All checkbox to the cell checkbox within the grid
                            cell.childNodes[j].checked =document.getElementById(parentid).checked;

c# Code

if (e.Row.RowType == DataControlRowType.Header)
                CheckBox chkall = e.Row.FindControl("chkall") as CheckBox;
                chkall.Attributes.Add("onclick","javascript:checkuncheck('"+ chkall.ClientID+"')");


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend