按下保存按钮,可以选择保存当前行,当前页和全部记录
- #region 保存
-
-
-
-
- protected void btnBC_Click(object sender, EventArgs e)
- {
- string save_cblJL = "";
- for (int i = 0; i < this.cblJL.Items.Count; i++)
- {
- if (this.cblJL.Items[i].Selected == true)
- {
- save_cblJL += this.cblJL.Items[i].Value + ",";
- }
- }
-
- string[] save_Excel = save_cblJL.Split(',');
-
- for (int j = 0; j < save_Excel.Length - 1;j++ )
- {
- if (save_Excel[j].Equals("全部记录"))
- {
- toExcelClk(gvwjdccx, 3);
- }
- else if (save_Excel[j].Equals("当前页"))
- {
- toExcelClk(gvwjdccx, 2);
- }
- else if (save_Excel[j].Equals("当前记录"))
- {
- toExcelClk(gvwjdccx, 1);
- }
- }
- }
- #endregion 保存
- #region 导出为Excel
-
-
-
-
-
- public override void VerifyRenderingInServerForm(Control control)
- {
-
- }
-
-
-
-
-
-
- private void ToExcel(Control ctl, string FileName)
- {
- HttpContext.Current.Response.Charset = "UTF-8";
- HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
- HttpContext.Current.Response.ContentType = "application/ms-excel";
- HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
- ctl.Page.EnableViewState = false;
- System.IO.StringWriter tw = new System.IO.StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(tw);
- ctl.RenderControl(hw);
- HttpContext.Current.Response.Write(tw.ToString());
- HttpContext.Current.Response.End();
- }
-
-
-
-
-
- private void toExcelClk(GridView gvw, int ckbSelect)
- {
- if (ckbSelect == 3)
- {
- gvw.AllowPaging = false;
- gvw.AllowSorting = false;
- gvw.DataSource = dt;
- gvw.DataBind();
- }
-
- else if (ckbSelect == 1)
- {
- gvw.AllowPaging = false;
- gvw.AllowSorting = false;
- int i = -1;
- foreach (GridViewRow gvwRow in this.gvw.Rows)
- {
- i++;
- if (((CheckBox)gvwRow.FindControl("ckbSelect")).Checked)
- {
- gvw.Rows[i].Visible = true;
- }
- else
- {
- gvw.Rows[i].Visible = false;
- }
- }
- }
- gvw.Columns[17].Visible = false;
- ToExcel(gvw, "jdccx.xls");
- gvw.AllowPaging = true;
- gvw.AllowSorting = true;
- gvw.Columns[17].Visible = true;
- gvw.DataSource = dt;
- gvw.DataBind();
- }
-
- #endregion 导出为Excel