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;

           }
     }

相關文章
相關標籤/搜索