Select rows using header checkbox in gridview

Here I am going to show a simple jQuery code that selects all the checkboxes from grid rows when header checkbox is selected. This is pretty common requirement. Also the code toggles header checkbox depending on whether all the rows have been selected.