Link to home
Start Free TrialLog in
Avatar of proginc
proginc

asked on

Footer data GridView

I am looping through a GridView to obtain Row, footer and header data. I can check the status of the DataControlRowType and get the rows, but cannot seem to get the footer.

<asp:TemplateField HeaderText="Amount" FooterStyle-Font-Bold="True"  SortExpression="Amount">
                <ItemTemplate>
                  <asp:Label ID="lblAmount" runat="server" Text='<%# GetAmount(decimal.Parse(Eval("Amount").ToString()))%>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                  <asp:Label ID="lblTotalAmount" runat="server" Text='<%# GetTotalAmount().ToString()%>'></asp:Label>
                </FooterTemplate>
                    <FooterStyle Font-Bold="True" />
                </asp:TemplateField>


This fails in code behind:

 foreach (GridViewRow row in this.gridView.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {

if( row.RowType == DataControlRowType.Footer)
{
}                    
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rpkhare
rpkhare
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of proginc
proginc

ASKER

Rows have a different control name from the footer, hence I need to confirm that I am reading the footer row before I use FindControl, how is this not working in my case. Header row detection does not work either.
rpkhare's suggestion goes straight to the footer row to find the control.

You don't need to loop through all of the rows to identify which one is the header row and which one is the footer row. There is only one header row and one footer row so you can access those rows specifically as rpkhare has suggested -

GridViewRow row = GridView1.FooterRow

Bear in mind also that header and footer rows cannot be data-bound.