Solved

Footer data GridView

Posted on 2013-05-12
3
494 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now