摘要:[Gridvew]在表尾加上總合(垂直計算)
寫在RowDataBound事件中:
int mysum1 = 0; //作為全域變數
if (e.Row.RowIndex >= 0) //if (e.Row.RowType == DataControlRowType.DataRow)
{
int value;
if(!int.TryParse(e.Row.Cells[9].Text,out value))
{value=0;}
mysum1 += value ;
}
if
(e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[9].Text = mysum1.ToString();
e.Row.BackColor = System.Drawing.Color.Chocolate;//設定這個footer的字顏色與背景色
e.Row.ForeColor = System.Drawing.Color.White;
}
另一段寫法,我是在網路上看到,分享一下(VB):
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
sum += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "某欄位"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "總計"
e.Row.Cells(1).Text = sum.ToString()
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
e.Row.Font.Bold = True
End If
End Sub
--
強烈建議購物網店或實體店家都必須使用關鍵字廣告or原生廣告來 將Yahoo上與聯播網的廣大流量導至自己的網站!
●Yahoo關鍵字廣告/原生廣告
◆Yahoo廣告方案介紹 : https://goo.gl/5k8FHW
◆Yahoo廣告剖析與運用 : http://goo.gl/4xjUJD