Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview which include a column which is checkbox . now i want to delete rows on the selected checkboxes's. how can i do this?
Posted

 
Share this answer
 
You can do this --
C#
foreach(GridViewRow  gvrow in gvDetails.Rows)     // iterate all the rows
{
    CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");     // find the checkbox control in that row
    if (chk != null & chk.Checked)       // check if checkbox if checked
    {
        string Id = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString() + ',';    // get the Id or any value using checked row in grid
        // fire delete query here based on Id
    }
}


-KR
 
Share this answer
 
Comments
Muhamad Faizan Khan 13-Mar-14 3:41am    
i am doing this but my code not full filling the codition why?
Muhamad Faizan Khan 13-Mar-14 3:42am    
if (chk != null & chk.Checked) this is not going true
Krunal Rohit 13-Mar-14 10:06am    
It is checking that checkbox is Checked or not. If it is, do the operation.

-KR

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