GridView添加统计行

 

protected void grd_bd_deptresults_RowDataBound(object sender, GridViewRowEventArgs e)

        {

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                //----------鼠标移动到每项时颜色交替效果

                e.Row.Attributes["onmouseover"] = "e=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'";

                e.Row.Attributes["onmouseout"] = "this.style.backgroundColor=e";

                //----------设置悬浮鼠标指针形状为小手"

                e.Row.Attributes["style"] = "Cursor:hand";

                //----------鼠标点击某行即选中某行

                e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grd_bd_deptresults, "Select$" + e.Row.RowIndex);

 

            }

            if (e.Row.RowType == DataControlRowType.Footer)//判断此行是否是页尾,如果是则开始统计数据

            {

                AddRow(e);               

            }  

            if(grd_bd_deptresults.FooterRow!=null)

            {

                grd_bd_deptresults.FooterRow.Visible = true;

            }

        }

 

 

     private void AddRow(GridViewRowEventArgs e)

        {

            decimal sc = 0;

            decimal dbp = 0;

            decimal itc = 0;

            decimal bp = 0;

            foreach (GridViewRow gvr in grd_bd_deptresults.Rows)

            {

                if (((Label)gvr.FindControl("lb_Year_Salary")) != null)

                {

                    sc = sc + Convert.ToDecimal(((Label)gvr.FindControl("lb_Year_Salary")).Text);

                    dbp = dbp + Convert.ToDecimal(((Label)gvr.FindControl("lb_Year_Performance")).Text);

                    itc = itc + Convert.ToDecimal(((Label)gvr.FindControl("lb_Post_Cost")).Text);

                    bp = bp + Convert.ToDecimal(((Label)gvr.FindControl("lb_Balance_Performance")).Text);

                }

                else if (((TextBox)gvr.FindControl("tb_Year_Salary")) != null)

                {

                    if (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("tb_Year_Salary")).Text))

                    {

                        sc = sc + Convert.ToDecimal(((TextBox)gvr.FindControl("tb_Year_Salary")).Text);

                        dbp = dbp + Convert.ToDecimal(((TextBox)gvr.FindControl("tb_Year_Performance")).Text);

                        itc = itc + Convert.ToDecimal(((TextBox)gvr.FindControl("tb_Post_Cost")).Text);

                        bp = bp + Convert.ToDecimal(((TextBox)gvr.FindControl("tb_Balance_Performance")).Text);

                    }

                }

            }

 

            e.Row.Cells.Clear();

 

            TableCell cell1 = new TableCell();

            cell1.ColumnSpan = 2;

            cell1.Text = "统计?";//(这里可以随便写,相当于已将单元格合并了?)

            cell1.HorizontalAlign = HorizontalAlign.Right;

            cell1.Style.Add("font-size", "10px");

            cell1.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell1);

 

            TableCell cell2 = new TableCell();

            cell2.ColumnSpan = 2;

            cell2.Text = "年部门总薪酬";//(这里可以随便写,相当于已将单元格合并了?)

            cell2.HorizontalAlign = HorizontalAlign.Center;

            cell2.Style.Add("font-size", "10px");

            cell2.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell2);

 

            TableCell cell3 = new TableCell();

            cell3.ColumnSpan = 1;

            cell3.Text = sc.ToString();//(这里可以随便写,相当于已将单元格合并了?)

            cell3.HorizontalAlign = HorizontalAlign.Center;

            cell3.Style.Add("font-size", "10px");

            cell3.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell3);

 

            TableCell cell4 = new TableCell();

            cell4.ColumnSpan = 2;

            cell4.Text = "部门累计年平衡业绩";//(这里可以随便写,相当于已将单元格合并了?)

            cell4.HorizontalAlign = HorizontalAlign.Center;

            cell4.Style.Add("font-size", "10px");

            cell4.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell4);

 

            TableCell cell5 = new TableCell();

            cell5.ColumnSpan = 1;

            cell5.Text = dbp.ToString();//(这里可以随便写,相当于已将单元格合并了?)

            cell5.HorizontalAlign = HorizontalAlign.Center;

            cell5.Style.Add("font-size", "10px");

            cell5.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell5);

 

            TableCell cell6 = new TableCell();

            cell6.ColumnSpan = 2;

            cell6.Text = "年部门岗位综合总费用?";//(这里可以随便写,相当于已将单元格合并了?)

            cell6.HorizontalAlign = HorizontalAlign.Center;

            cell6.Style.Add("font-size", "10px");

            cell6.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell6);

 

            TableCell cell7 = new TableCell();

            cell7.ColumnSpan = 1;

            cell7.Text = itc.ToString();//(这里可以随便写,相当于已将单元格合并了?)

            cell7.HorizontalAlign = HorizontalAlign.Center;

            cell7.Style.Add("font-size", "10px");

            cell7.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell7);

 

            TableCell cell8 = new TableCell();

            cell8.ColumnSpan = 2;

            cell8.Text = "年公司平衡业绩量;//(这里可以随便写,相当于已将单元格合并了?)

            cell8.HorizontalAlign = HorizontalAlign.Center;

            cell8.Style.Add("font-size", "10px");

            cell8.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell8);

 

            TableCell cell9 = new TableCell();

            cell9.ColumnSpan = 1;

            cell9.Text = bp.ToString();     //(这里可以随便写,相当于已将单元格合并了)

            cell9.HorizontalAlign = HorizontalAlign.Center;

            cell9.Style.Add("font-size", "10px");

            cell9.Style.Add("font-weight", "bold");

            e.Row.Cells.Add(cell9);

            e.Row.CssClass = grd_bd_deptresults.FooterStyle.CssClass;

 

        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值