我在转发器中有一个gridview。在gridview中,有一列TXN_AMT,其中包含一个链接按钮。当我点击链接按钮的小计和格式或选择页面索引时,计算不会显示正确的值。
全局变量
Dim dSubtTtlTxnAmt,grandTotal As Double
转发器和网格视图代码
Public Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Header Then Exit Sub
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim GV As GridView = e.Item.FindControl("GV")
Dim ObjDS As ObjectDataSource = e.Item.FindControl("ObjDS")
ObjDS.SelectParameters.Clear()
ObjDS.SelectParameters.Add("dteDateStart", DbType.Date, Param.dteDateStart.ToString())
ObjDS.SelectParameters.Add("dteDateEnd", DbType.Date, Param.dteDateEnd.ToString())
GV.PageSize = 10
' Reset to 0, to prevent amount use by next record in repeater
dSubtTtlTxnAmt = 0
GV.DataSourceID = "ObjDS"
GV.DataKeyNames = New String() {"ID"}
GV.DataBind()
End If
End Sub
Private Sub GenerateFooter(ByVal oGV As RenderGridViewDataRow, ByVal sender As Object)
Dim SubTotalRow As New List(Of RenderGridViewDataRow.TotalRowField)
SubTotalRow.Add(New RenderGridViewDataRow.TotalRowField(dSubtTtlTxnAmt, RenderGridViewDataRow.TotalRowField.DataType.Decimal, 2))
oGV.CreateTotalRow(SubTotalRow, sender, "Sub Total ", 3
Dim GrandTotalRow As New List(Of RenderGridViewDataRow.TotalRowField)
GrandTotalRow.Add(New RenderGridViewDataRow.TotalRowField(ViewState("grandTotal"), RenderGridViewDataRow.TotalRowField.DataType.Decimal, 2))
oGV.CreateTotalRow(GrandTotalRow, sender, "Grand Total ", 3
End Sub
Public Sub ObjDS_Selected(sender As Object, e As ObjectDataSourceStatusEventArgs)
' ## Assign value to variables
grandTotal = e.OutputParameters.Item("GRAND_TOTAL")
' ## Set Grandtotal to viewstate
ViewState.Add("grandTotal", grandTotal)
End Sub
Public Sub GV_RowCreated(sender As Object, e As GridViewRowEventArgs)
Dim oGv As New RenderGridViewDataRow
If e.Row.RowType = ListItemType.Footer Then
' Generate footer
GenerateFooter(oGv, sender)
End If
' Render gridview data row
oGv.RenderGridViewDataRow(e, sender)
End Sub
Public Sub GV_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Then
' Calculate subtotal
dSubtTtlTxnAmt += CDec(e.Row.DataItem("TXN_AMT"))
End If
End Sub