0

値をフッターのラベルに表示できません。以下はコードです

Aspx

<asp:GridView ID="gvallAccount" runat="server" AutoGenerateColumns="False" Width="589px"
                        OnRowDataBound="gvallAccount_RowDataBound" OnRowCommand="gvallAccount_RowCommand">
                        <Columns>
                            <asp:TemplateField Visible="False">
                                <ItemTemplate>
                                    <asp:Label ID="lblAccountID" runat="server" Text='<%# Bind("ProductAccountID") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Name" Visible="True">
                                <ItemTemplate>
                                    <asp:Label ID="lblProductName" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Account Number" Visible="True">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkAccCode" runat="server" Text='<%# Bind("ProductAccountCode") %>'
                                        OnClick="lnkAccCode_Click" CommandName="gotoLink"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Account Value(KES)" Visible="True">
                                <ItemTemplate>
                                    <asp:Label ID="lblBalance" runat="server" Text='<%# Bind("BalanceToDate") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="lblTotal" runat="server"></asp:Label>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

C# Code 

 protected void gvallAccount_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                decimal rowTotal = Convert.ToDecimal
                            (DataBinder.Eval(e.Row.DataItem, "BalanceToDate"));
                grdTotal = grdTotal + rowTotal;
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblTotal = (Label)e.Row.FindControl("lblTotal");
                lblTotal.Text = grdTotal.ToString();
            }
        }
        catch (Exception Ex)
        {
            logger.Error("gvallAccount_RowDataBound : " + Ex.Message);
        }
    }
4

1 に答える 1

0

GridViewタグにShowFooter="True"属性が必要です。

<asp:GridView ID="gvallAccount" runat="server" AutoGenerateColumns="False" Width="589px"
                    OnRowDataBound="gvallAccount_RowDataBound" OnRowCommand="gvallAccount_RowCommand" ShowFooter="True">
于 2012-10-24T18:31:10.253 に答える