Solved

Footer data GridView

Posted on 2013-05-12
3
491 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

17 Experts available now in Live!

Get 1:1 Help Now