Gridview get Checkbox.Checked value

后端 未结 7 648
北荒
北荒 2020-12-17 10:23

I have a GridView that has 10 columns populated by CheckBoxes. But instead of using FindControl() is there a way to get the CheckBox.Checked value

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 10:55

    For run all lines of GridView don't use for loop, use foreach loop like:

    foreach (GridViewRow row in yourGridName.Rows) //Running all lines of grid
    {
        if (row.RowType == DataControlRowType.DataRow)
        {
             CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
    
             if (chkRow.Checked)
             {
                  //if checked do something
             }
        }
    }
    

提交回复
热议问题