直放站页脚总 [英] Repeater Footer Total

查看:146
本文介绍了直放站页脚总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点难倒,为什么这不工作,我可能是做错了什么。

I'm a bit stumped as to why this isn't working, I may be doing something wrong.

我有金额列值的中继器,我想说明的总该列的中继器的脚注。

I have a repeater with values in the Amount column, I want to show the total of this column in the footer of the repeater.

问题是,总爱炫耀0,并且不添加行的值了。

The problem is that the Total is always showing 0 and not adding the values of the rows up.

code背后

Protected Sub reCosts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles reCosts.ItemDataBound

        Dim rowView As System.Data.DataRowView
        rowView = CType(e.Item.DataItem, System.Data.DataRowView)

        Dim CostsTotal As Decimal

        If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then


            Dim lCostAmount As Literal = CType(e.Item.FindControl("lCostAmount"), Literal)
            Dim CostAmount As Decimal = rowView("Amount")
            lCostAmount.Text = CostAmount.ToString("C2")


            CostsTotal += CostAmount


        ElseIf e.Item.ItemType = ListItemType.Footer Then

            Dim lCostsTotal As Literal = CType(e.Item.FindControl("lCostsTotal"), Literal)
            lCostsTotal.Text = CostsTotal.ToString("C2")

        End If

    End Sub

任何帮助将是AP preciated。

Any help would be appreciated.

学家

推荐答案

正在发生的事情是 CostsTotal 变量被声明的每个项目势必时间和复位至零当它被绑定页脚。

What is happening is the CostsTotal variable is being declared each time an item is bound and resetting to zero when it is binding the footer.

您需要添加保存在ViewState中像这样的属性:

You need to add a property that is saved in ViewState like this:

Public Property [CostsTotal] As String
   Get
       Return CStr(ViewState("CostsTotal"))
   End Get
   Set
       ViewState("CostsTotal") = Value
   End Set
End Property

另外,还要确保你删除此行:

Also make sure you remove this line:

Dim CostsTotal As Decimal

这篇关于直放站页脚总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆