protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { page = ViewState["page"] == null ? 0 : (int)ViewState["page"]; btnSelect_All.Text = "全选"; //添加数据 btnAddProject.OnClientClick = WindowHonor.GetShowReference("Add_HonorTitle.aspx"); //修改数据 btnUpdate.OnClientClick = GridHonor.GetNoSelectionAlertReference("请至少选择一项!"); BindData(); btnDelete.Enabled = false; DropDownListYearandLevel.Enabled = false; TBNameandAgency.Enabled = false; } }
//全选按钮 protected void btnSelect_All_Click(object sender, EventArgs e) { GridHonor.SelectAllRows(); int[] select = GridHonor.SelectedRowIndexArray; int m; //取整数(不是四舍五入,全舍) int Pages = (int)Math.Floor(Convert.ToDouble(GridHonor.RecordCount / this.GridHonor.PageSize)); if (GridHonor.PageIndex == Pages) { m = (GridHonor.RecordCount - this.GridHonor.PageSize * GridHonor.PageIndex); } else { m = this.GridHonor.PageSize; } bool isCheck = false; for (int i = 0; i < m; i++) { if (CBoxSelect.GetCheckedState(i) == false) { isCheck = true; } } if (isCheck) { foreach (int item in select) { CBoxSelect.SetCheckedState(item, true); } btnDelete.Enabled = true; btnSelect_All.Text = "取消全选"; } else { foreach (int item in select) { CBoxSelect.SetCheckedState(item, false); } btnDelete.Enabled = false; btnSelect_All.Text = "全选"; } }