Get the indexes of selected rows in GridView

泪湿孤枕 提交于 2019-12-03 03:40:03

try this:

protected void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
    CheckBox checkbox = (CheckBox)sender;
    GridViewRow row = (GridViewRow)checkbox.NamingContainer;
    if (checkbox.Checked == true) {
        row.BackColor = System.Drawing.Color.Red;
        mygridview.Columns(0).Visible = false;
    }
}

You can loop through the GridView rows and use FindControl to retrieve the Checkbox and then get the IsChecked property on them.

foreach (GridViewRow row in grid.Rows)
{
  CheckBox check = (CheckBox)row.FindControl("CheckboxID");

  if (CheckBox1.Checked)
  {
   ...
  } 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!