Getting Checked rows from gridview in asp.net

痴心易碎 提交于 2019-11-30 15:20:36
Genzume

You could iterate through the GridViewRows and check if the CheckBox is checked using something like the following

Edit from comments, fixed small bugs. Thanks guys. (3/20/2013):

foreach (GridViewRow row in yourGridViewID.Rows)
{
    CheckBox check = (CheckBox)row.FindControl("CheckBoxName");

    if (check.Checked)
    {
        //Take Row information from each column (Cell) and display it
    }
    else
    {
        //Display in seperate area
    }
}

The index is going to be the column number starting from 0, going left to right of which column holds the CheckBox. You need to make sure the CheckBox has an ID name which is used at CheckBoxName. If you don't have an ID for that, you can also use

CheckBox check = (CheckBox)row.Cells[index].Controls[0];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!