实现GridView里的checkbox 全选功能:(后台实现)

如何获取GridView中HeaderTemplate里面控件的值(附加checkbox全选功能)在头模版里有个CheckBox1,如何得到这个控件的值,事件由控件CheckBox1来AutoPostBack

(!!!!!!!!!)
CheckBox cbAll = (CheckBox) GridView1.HeaderRow.FindControl("CheckBox1");

实现GridView1里的checkbox 全选功能:(后台实现)


后台代码
  protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
           
                if (((CheckBox)GridView1.HeaderRow.FindControl("CheckBox2")).Checked == true)
                {
                    cbox.Checked = true;
                }
                else
                {
                    cbox.Checked = false;
                }
               
              
            }


        }


前台代码
                 AutoGenerateColumns="False" ForeColor="Black" Width="100%" BackColor="#BBBBBB"
              >
              
              
                  
                      
                           全选                                oncheckedchanged="CheckBox2_CheckedChanged" />
                      

                      
                          
                      

                  

你可能感兴趣的:(.NET,ASP.NET)