• gridview页脚汇总,页头合并


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class EMP_emp_info : System.Web.UI.Page
    {
        SunzmxLib.Sunzmx sunzmx = new SunzmxLib.Sunzmx("HRDB");
        HRDB.Tbempinfo info = new HRDB.Tbempinfo();
        public DataTable dtSum; 
        protected void Page_Load(object sender, EventArgs e)
        {      
            if (!IsPostBack)
            {  
                voidtable();
            }
        }

        private void voidtable()
        {
            IList list1 = sunzmx.QueryBean("from Tbempinfo c order by c.Id desc");
           
           
            //dtSum = lst[0];
            list1.Insert(0, new HRDB.Tbempinfo());
            grvEmp.DataSource = list1;
            grvEmp.DataBind();       
        }   
        protected void grvEmp_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Session["emp_info_ID"] = grvEmp.DataKeys[e.NewEditIndex].Value;
           
          
            Response.Redirect("emp_info_edit.aspx");
        }
       
        protected void img_btn_info_Cz_Click(object sender, ImageClickEventArgs e)
        {
            int flag = -1;

            Session["emp_info_ID"] = flag.ToString();
           
            Response.Redirect("emp_info_edit.aspx");
        }
        protected void grvEmp_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            info.Id = Convert.ToInt32(grvEmp.DataKeys[e.RowIndex].Value.ToString());
            sunzmx.deleteBean(info);
            voidtable();
        }


        protected void grvEmp_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvEmp.PageIndex = e.NewPageIndex;
            voidtable();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
            Response.ContentType = "application/vnd.xls";//设置输出文件类型为excel文件。       
            this.EnableViewState = false;           
            System.IO.StringWriter ostringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter ohtmlWrite = new HtmlTextWriter(ostringWrite);       
            //this.grvEmp.ShowFooter = false;
            this.grvEmp.AllowPaging = false;
            //this.grvEmp.Columns[5].Visible = false;
            if (CheckBox1.Checked)
            {
                this.grvEmp.Columns[0].Visible = false;
            }
            voidtable();
            this.grvEmp.RenderControl(ohtmlWrite);
            Response.Write(ostringWrite.ToString());
            Response.End();
            this.grvEmp.AllowPaging = true;
            this.grvEmp.ShowFooter = true;
            this.grvEmp.Columns[5].Visible = true;
            this.grvEmp.Columns[0].Visible = true;
            voidtable();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            // Confirms that an HtmlForm control is rendered for
        }
        protected void grvEmp_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            IList lst = sunzmx.QueryBean("select sum(c.NL) from  Tbempinfo c");               
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[0].Text = "合计";
                e.Row.Cells[3].Text = lst[0].ToString();
            }
        }
        protected void grvEmp_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.Header)
            //{
                //GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
                //rowHeader.BackColor = System.Drawing.Color.White;
                //rowHeader.Font.Bold = true;
                //TableCellCollection cells = e.Row.Cells;
                //TableCell headerCell = new TableCell();
                //headerCell.Text = "";
                //rowHeader.Cells.Add(headerCell);
                //headerCell = new TableCell();
                //headerCell.Text = "学生成绩";
                //headerCell.ColumnSpan = cells.Count - 1;
                //headerCell.HorizontalAlign = HorizontalAlign.Center;
                //rowHeader.Cells.Add(headerCell);
                //rowHeader.Visible = true;
                //GridView1.Controls[0].Controls.AddAt(0, rowHeader);

            //}
            if (e.Row.RowType == DataControlRowType.Header)
            {
                GridViewRow rowHeader = new GridViewRow(0,0,DataControlRowType.Header,DataControlRowState.Normal);
                rowHeader.Font.Bold = true;
                TableCellCollection cells = e.Row.Cells;
                TableCell headerCell = new TableCell();
                headerCell.Text = "";
                rowHeader.Cells.Add(headerCell);
                headerCell = new TableCell();
                headerCell.Text = "基本信息";
                headerCell.ColumnSpan = cells.Count - 1;
                headerCell.HorizontalAlign = HorizontalAlign.Center;
                rowHeader.Cells.Add(headerCell);
                rowHeader.Visible = true;
                grvEmp.Controls[0].Controls.AddAt(0,rowHeader);
            }

        }
    }

  • 相关阅读:
    centos7 做rails 执行rails server 报错
    centos 7 安装 rvm 超时
    centos7 打造基于python语言Selenium2自动化开发环境
    RubyMine8 安装
    linux 下安装 RZ SZ命令 以及使用
    centos 7.2 安装mysql 修改 初始密码
    win10系统配置FTP
    Windows环境安装MySQL8.0.11
    IntelliJ IDEA 2017 上传本地项目至码云
    IntelliJ IDEA 2017.3 搭建一个多模块的springboot项目(三)
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/2689053.html
Copyright © 2020-2023  润新知