GridView全选

两个CheckBox一个在header一个在item(chbItem)
设置header的CheckBox的AutoPostBack为True引发以下事件
  protected void chbAll_CheckedChanged(object sender, EventArgs e)
    {
        if (((CheckBox)sender).Checked)//选中当前页面所有行
        {
            foreach (GridViewRow row in gvMusic.Rows) //gvMusic.Rows中的Rows只计当前页(分页情况下)的行数,如果
                                                                                   //是数据的所用行,用Items.Count();
            {
                ((CheckBox)row.Cells[0].FindControl("chbItem")).Checked = true;
            }
        }
        else //清空当前页面所有行选中状态
        {
            foreach (GridViewRow row in gvMusic.Rows)
            {
                ((CheckBox)row.Cells[0].FindControl("chbItem")).Checked = false;
            }
        }
    }

转载于:https://my.oschina.net/secyaher/blog/274351

猜你喜欢

转载自blog.csdn.net/weixin_33918114/article/details/91966855
今日推荐