Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to figure out how to have a "select all" button on each row of a gridview that will using javascript or jquery select all of the check boxes on that row only. I have seen many ways to select all of the check boxes in a gridview but I want to only select those check boxes on the row that the "select all" button was clicked. Any ideas would be appreciated.

jp
Posted
Comments
Ankur\m/ 28-Aug-10 0:25am    
John, please do not add an answer if it's not an answer. You should use 'Add Comment' feature below an answer to discuss with the user. In this way he also gets notified. I am moving your answer to the comment section.
Sandeep Mewara 28-Aug-10 6:03am    
Your last part is not clear.
Please re-phrase: "I have seen many ways to select all of the check boxes in a gridview but I want to only select those check boxes on the row that the "select all" button was clicked. "
Ankur\m/ 28-Aug-10 7:39am    
He means, selecting checkboxes in a column by selecting the header checkbox is a common scenario. But he needs to select all checkboxes in a row by selecting a button in that particular row.
I hope it's clear now.

Anyway I think my answer answers his question.
Ankur\m/ 28-Aug-10 9:47am    
You may also consider up-voting the answer. :)

 
Share this answer
 
Comments
john_paul 28-Aug-10 8:47am    
Thanks for your help, this is what I was looking for.
This is such a Google question...

It can be JavaScripted

protected void chkbSelectAll_CheckedChanged(object sender, EventArgs e)
    {
        bool chkFlag = false;
        if (chkbSelectAll.Checked) chkFlag = true;
        foreach (GridViewRow dr in gvProducts.Rows)
        {
            CheckBox chk = (CheckBox)dr.Cells[0].FindControl("Select");
            chk.Checked = chkFlag;
        }
    }



Does this help
 
Share this answer
 
v2
Comments
Ankur\m/ 28-Aug-10 0:26am    
[moved from answer]
john_paul wrote: If this is such a google question then why did you give an answer that does not even begin to answer the question I asked.
Ankur\m/ 28-Aug-10 0:29am    
DD, you say it can be JavaScripted, and you give an event which fires on the server.
The code that you have given needs postback. Moreover, it also needs AutoPostBack property of the CheckBox to be set to true, which is not the best practice.
This is not at all a JavaScript function.

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