Allie Hart
Allie Hart

Reputation: 159

Grid view footer not showing

I am building a gridview from an arraylist and want to include a footer to the bottom.

This is my c# code

gvOrder.DataSource = orderItemList; 
gvOrder.DataBind(); 
gvOrder.ShowFooter = true; 
gvOrder.Columns[0].FooterText = "Totals:"; 
gvOrder.Columns[2].FooterText = Convert.ToString(quantity); 
gvOrder.Columns[4].FooterText = Convert.ToString(priceTotal);

Here is my asp code

<asp:GridView ID="gvOrder" runat="server" AutoGenerateColumns="False" ShowFooter="True">
    <Columns>
        <asp:BoundField DataField="ItemTitle" HeaderText="Title" />
        <asp:BoundField DataField="ItemFormat" HeaderText="Format" />
        <asp:BoundField DataField="ItemQuantity" HeaderText="Quantity" /> 
        <asp:BoundField DataField="ItemPrice" HeaderText="Price" />
        <asp:BoundField DataField="ItemTotal" HeaderText="Total" />
    </Columns>
</asp:GridView>

Upvotes: 1

Views: 1679

Answers (1)

VDWWD
VDWWD

Reputation: 35514

The order of things matter. You have to set the footer values before DataBind() is called.

gvOrder.Columns[0].FooterText = "Totals:"; 
gvOrder.Columns[2].FooterText = Convert.ToString(quantity); 
gvOrder.Columns[4].FooterText = Convert.ToString(priceTotal);

gvOrder.DataSource = orderItemList; 
gvOrder.DataBind();
gvOrder.ShowFooter = true; 

But you can set the values of the Footer Row after DataBind if you specify the footerrow cells instead of the Colums.

gvOrder.FooterRow.Cells[1].Text = "After DataBind";

Upvotes: 2

Related Questions