RT..
我现在需要得到Header Template里面的CheckBox控件的Checked属性..不只如何获得

解决方案 »

  1.   

    这样试试看: DataGrid grid = this.dataGrid1;
    for (int i = 0; i < grid.Rows.Count; i++)
    {
    CheckBox checkBox = grid.Rows[i].FindControl("checkBox") as CheckBox;
    if (checkBox != null && checkBox.Checked)
    {
    object value = grid.DataKeys[i].Value;
    }
    }
      

  2.   

    未将对象引用设置到对象的实例。 
    我用的是C#语言写的..
    ((CheckBox)this.DataGrid1.Items[0].FindControl("CheckBox2")).Checked
    然后报错了
    这样不行
      

  3.   

    ((CheckBox)this.DataGrid1.FindControl("CheckBox2")).Checked 
    也不行
      

  4.   

            
            foreach (Control con in this.GridView1.HeaderRow.Controls) {
                if (null != con)
                {
                    if (null != con.FindControl("CheckBox1"))
                    {
                        CheckBox theCheck = (CheckBox)con.FindControl("CheckBox1");
                        theCheck.Checked = true;
                    }
                }
            }
      

  5.   

     protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow gr in GridView2.Rows)
            {
                CheckBox chk = (CheckBox)gr.Cells[0].FindControl("Chkitem");            if (!chk.Checked)
                {
                    chk.Checked = true; 
                }
                else
                {
                    chk.Checked = false; 
                }        }
        }