1
我正在生成一个总计来自转发器的一些列并将其放入转发器的页脚的报告。ASP.NET公共属性ViewState
我已经通过设置一个公共属性为如下每个总价值做到了这一点:
Public Property [CostTotal] As Decimal
Get
Return CStr(ViewState("CostTotal"))
End Get
Set(ByVal value As Decimal)
ViewState("CostTotal") = value
End Set
End Property
有对报告中的一些过滤选项,使用户可以选择日期等,以滤除报告。
当有人这样做时,公共属性值仍然保留(因为它在视图状态)设置的任何过滤器,因此总数不会累加。有没有办法将公共属性重新设置为0,如果页面被重新发布或者完全采用这种方式?
的ItemDataBound代码
Protected Sub reMileage_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles reMileage.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rowView As System.Data.DataRowView
rowView = CType(e.Item.DataItem, System.Data.DataRowView)
Dim lMileageDate As Literal = CType(e.Item.FindControl("lMileageDate"), Literal)
If Not IsDBNull(rowView("Date")) Then
Dim MileageDate As Date = rowView("Date")
lMileageDate.Text = MileageDate.ToString("dd/MM/yyyy")
End If
Dim lMileageDescription As Literal = CType(e.Item.FindControl("lMileageDescription"), Literal)
If Not IsDBNull(rowView("Location")) Then
lMileageDescription.Text = Format.TextboxHtmlDecode(rowView("Location"))
End If
Dim lMileageRate As Literal = CType(e.Item.FindControl("lMileageRate"), Literal)
If Not IsDBNull(rowView("Rate")) Then
Dim MileageRate As Decimal = rowView("Rate")
lMileageRate.Text = MileageRate.ToString("N3")
End If
Dim lMileageMiles As Literal = CType(e.Item.FindControl("lMileageMiles"), Literal)
If Not IsDBNull(rowView("Mileage")) Then
Dim MileageMiles As Decimal = rowView("Mileage")
lMileageMiles.Text = MileageMiles.ToString("N2")
MileageTotal += MileageMiles
'Response.Write(MileageTotal & "<br>" & MileageMiles)
End If
Dim lMileageCost As Literal = CType(e.Item.FindControl("lMileageCost"), Literal)
If Not IsDBNull(rowView("Cost")) Then
Dim MileageCost As Decimal = rowView("Cost")
lMileageCost.Text = MileageCost.ToString("C2")
CostTotal += MileageCost
End If
ElseIf e.Item.ItemType = ListItemType.Footer Then
Dim lMileageTotal As Literal = CType(e.Item.FindControl("lMileageTotal"), Literal)
lMileageTotal.Text = MileageTotal.ToString("N2")
Dim lCostTotal As Literal = CType(e.Item.FindControl("lCostTotal"), Literal)
lCostTotal.Text = CostTotal.ToString("C2")
End If
End Sub
感谢您的帮助。 J.
我想我刚刚整理它,不知道这是很好的做法,但我可以只申报reMileage_ItemDataBound子外的总变量,谢谢你的帮助。 – JBoom