Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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" >

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

       </asp:TemplateField>
 </Columns>

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

1 Answer 1

up vote 0 down vote accepted

I found it. I changed the code:

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

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

}
share|improve this answer

Your Answer

 
discard

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.