Solved

Footer data GridView

Posted on 2013-05-12
3
500 Views
Last Modified: 2013-05-13
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

0
Comment
Question by:proginc
3 Comments
 
LVL 8

Accepted Solution

by:
rpkhare earned 500 total points
ID: 39159679
Not sure but are you trying to get the Footer row data?

In that case you can get Footer Row data as below:

 
       string CustomerName = string.Empty;
       GridViewRow row = GridView1.FooterRow; 
        CustomerName = ((TextBox)row.FindControl("txtCustomer")).Text;

Open in new window

0
 
LVL 1

Author Comment

by:proginc
ID: 39159994
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.
0
 
LVL 12

Expert Comment

by:duttcom
ID: 39160238
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question