我有一個網格視圖,其中包含小時作爲其中一列..現在,我需要在頁腳總小時數(所有行的小時數總和)..我們如何添加?請幫助gridview頁腳
1
A
回答
1
0
隨着每一行被渲染(即當它被稱爲RowDataBound事件),你需要保持運行每行的總時間,下面的代碼應該這樣做。 (來自MSDN站點的示例的修改版本)
一旦找到頁腳的RowDataBound事件,就會顯示總小時數。
' This will keep the running total for the number of hours, and should be placed at the top of your page class
Dim Hours as Integer
Sub detailsGridView_RowDataBound(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Hours += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Hours"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Totals Hours:"
e.Row.Cells(1).Text = Hours.ToString("c")
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End Sub
1
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' 検索を行う
Dim cn As New SqlConnection(_
SqlDataSource1.ConnectionString)
Dim da As New SqlDataAdapter(_
"SELECT count(*), sum(age) FROM person", cn)
Dim dt As New DataTable
da.Fill(dt)
' 人數と年齢の合計を取得する
Dim n As Integer = CType(dt.Rows(0)(0), Integer) ' 人數
Dim sum As Integer = CType(dt.Rows(0)(1), Integer) ' 年齢の合計
' フッターに設定する
GridView1.Columns(0).FooterText = String.Format("{0}人", n)
GridView1.Columns(1).FooterText = String.Format("合計{0}", sum)
End If
End Sub
End Class
0
採取網格視圖元素的數據表,計算總每一列的編程方式, 使網格視圖頁腳模板,插入標籤,發現綁定您想要的事件和標籤數據。
相關問題
- 1. Gridview頁腳
- 2. 顯示gridview頁腳
- 3. 在gridview頁腳dropdownlist框
- 4. 添加頁腳到GridView Android
- 5. Gridview不顯示頁腳?
- 6. GridView頁腳不工作
- 7. gridview固定頁眉和固定頁腳
- 8. GridView的固定頁眉和頁腳
- 9. 添加頁眉/頁腳的GridView
- 10. 更改gridview頁腳頁腳中所選頁碼的顏色
- 11. 在GridView中更改頁腳文本
- 12. 添加多個頁腳行到Gridview
- 13. 如何添加頁腳到Gridview
- 14. Gridview - 添加行按鈕使用頁腳
- 15. 有兩行頁腳的Asp.Net GridView
- 16. Gridview頁腳的單獨數據源
- 17. 在updatepanel中顯示Gridview頁腳
- 18. 動態添加頁腳到ASP.NET GridView
- 19. JavaScript中的Gridview頁腳行文本框
- 20. ASP.NET添加多個頁腳行的GridView
- 21. [javascript]驗證Gridview頁腳複選框
- 22. GridView的頁腳總使用LINQ
- 23. Gridview頁腳數據格式字符串
- 24. Dropview在Gridview頁腳不填充
- 25. 添加行使用頁腳中的GridView
- 26. 在Gridview的頁腳中顯示gridview的記錄總數
- 27. 需要在gridview外的文本框gridview中的頁腳總數
- 28. 帶有固定頁眉和頁腳的asp.net可滾動gridview
- 29. GridView在頁腳中下拉頁面大小
- 30. 使用Linq to Sql在空GridView上顯示頁眉和頁腳