CheckBox的CheckedChanged事件获取DataGrid选中行的值

在protected void CheckBox1_CheckedChanged事件中写代码: spa

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)事件

{string

      CheckBox check = (CheckBox)sender; object

        //System.Web.UI.WebControls.TableCell dcf = (System.Web.UI.WebControls.TableCell)check.Parent;
        //DataGridItem dgItem = (DataGridItem)dcf.Parent;
        DataGridItem dgItem = (DataGridItem)check.Parent.Parent;
        string id = dgItem.Cells[1].Text;
        if (check.Checked)
        {grid

            string ID = dgItem.Cells[1].Text;遍历

            string name = dgItem.Cells[2].Text;
        }        co

}void

附加:若是要遍历Datagrid中的CheckBox是否选中ab

     for (int j = 0; j < Datagrid.Rows.Count; j++)
    {
         CheckBox chbox = Datagrid.Rows[j].FindControl("CheckBox1"as CheckBox;
          if (chbox.Checked)
           {
                string ID = Datagrid.Rows[j].Cells[1].Text;tag

                string name = Datagrid.Rows[j].Cells[2].Text;

           }
     }

相关文章
相关标签/搜索