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;
}