SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a webpart with SpGridView.

<SharePoint:SPGridView ID="grid" AllowSorting="true" AllowFiltering="true" CssClass="ms-listviewtable"
runat="server" AutoGenerateColumns="false" AllowPaging="True" HeaderStyle-Width="20px" >

            <asp:CheckBox ID="select" runat="server" />
        <asp:CheckBox ID="selectionCheckBoxHeader" runat="server" OnClick="checkAllCheckBoxes(this)" />


I add checkbox to header for select all rows of SpGridView.

I use javascrpt for select all.

function checkAllCheckBoxes(invoker) {  
var gridView = document.getElementById('<%# grid.ClientID %>');
for (var i = 1; i < gridView.rows.length; i++) {
    var rowElement = gridView.rows[i].cells[0];
    for (var j = 0; j < rowElement.childNodes.length; j++) {
        if (rowElement.childNodes[j].type == "checkbox") {
            rowElement.childNodes[j].checked = invoker.checked;

Problem is :

getElementById don't find SpGrid !!!

share|improve this question
up vote 0 down vote accepted

I found it. I changed the code:

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
    CheckBox cb = e.Row.Cells[0].FindControl("selectionCheckBoxHeader") as CheckBox;

   cb.Attributes.Add("onclick", "checkBoxChange(this,"+grid.ClientID+")");

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.