dataGridView 全选 和 全清 ??

解决方案 »

  1.   

     private void rabtnNO_Click(object sender, EventArgs e)
            {
                if (rabtnNO.Checked == true)
                {
                    int n = gridview.Rows.Count;
                    if (n != 0)
                        for (int i = 0; i < n; i++)
                            gridview.Rows[i].Cells[Colcheck.Index].Value = false;
                }
            }
      

  2.   

    for (int i = 0; i < dataGridView.Rows.Length; i++)   
    {
        dataGridView.Rows[i].Selected = true; //true: 全选; false: 全清...
    }
      

  3.   

    cs:
    protected void Button1_Click(object sender, EventArgs e)
      {
        Ret1.Text = "";
        foreach (GridViewRow gvr in GridView1.Rows)
        {
          CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
          ch.Checked = true;
        }
      }
    JS:
    protected void CheckAll(object sender, EventArgs e)
      {
        CheckBox cbx = (CheckBox)sender;
        foreach (GridViewRow gvr in GridView1.Rows)
        {
          CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
          ch.Checked = cbx.Checked;
        }
      }