我需要一些东西为我的GridView添加一个累积的总列

时间:2015-02-03 05:25:59

标签: c# asp.net gridview

当我尝试该代码时给了我很多错误,我需要添加一个累积的总列到我的GridView,它将显示该行中一个数字列的累计总数。像那样Running / Cumulative total in GridView column我需要在这里解决的问题,但代码不起作用

 debit  |credit |Total         
 2      | 0     | 2
 0      | 1     | 3
-0.5    | 0     | 2.5
 0      |1.5    |4

the errors shown whem I tried to use the code in that question

我的HTML

                               

        <asp:TemplateField HeaderText="amount">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblTotal" Text=""></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>


         <asp:TemplateField HeaderText="debit">
            <ItemTemplate>
                <asp:Label ID="debit" runat="server" Text='<%# (Eval("stat_flag").ToString() =="d" ) ? Eval("stat_amount"): "0.00" %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

              <asp:TemplateField HeaderText="credit">
            <ItemTemplate>
                <asp:Label ID="credit" runat="server" Text='<%# (Eval("stat_flag").ToString() =="c" ) ? Eval("stat_amount"): "0.00" %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

我的代码错误为enter image description here

1 个答案:

答案 0 :(得分:0)

如果你试图找到rowtype等于Footer(DataControlRowType.Footer)的标签,你需要使用它:

<asp:TemplateField>
    <FooterTemplate>
        <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
    </FooterTemplate>
</asp:TemplateField>