在GridView中找CheckBox控件

protected void btnConfig_Click(object sender, EventArgs e)
{
        foreach (GridViewRow row in GridViewInfo.Rows)
        {
            CheckBox dirCheckBox = (CheckBox)row.FindControl("DirCheak");
            if (dirCheckBox != null)
            {
                if (dirCheckBox.Checked == true)
                {
                    myBFUser.DeleteFlatInfo(int.Parse(GridViewInfo.DataKeys[row.RowIndex].Value.ToString()));
                }
            }
        }
        BindGridView();
}

同时还要设置GridView的DataKeyNames属性(绑定数据库字段ID)

原文地址:https://www.cnblogs.com/zhc088/p/677469.html