Solved

C#

Posted on 2008-09-29
6
202 Views
Last Modified: 2012-05-05
I want to add the values in the column and place the result in the gridview footer row. I'm using below code but its getting fired before i fill the gridview and going into header row if statement.
Could you please tell me which event to use to get the values in the footer row.
 
Note: The values i'm adding are in the label inside the gridview. I need to manually enter the values inside the gridview and perform calculations.

protected void GridViewHW_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataRowView tabledata = e.Row.DataItem as DataRowView;
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TotalHWCost = 0;
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TotalHWCost += Convert.ToInt16(tabledata[3]);
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label TotalHWCostref = e.Row.FindControl("LabelTotalHardwareCost") as Label;
            TotalHWCostref.Text = "$"+TotalHWCost.ToString();
        }

    }
0
Comment
Question by:MRManthani
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:johnaryan
ID: 22597661
There is an OnRowAdded event that you could use....
0
 

Author Comment

by:MRManthani
ID: 22597932
I didnt find any onrowadded event but i can view onrowcommand,onrowcreated...Can I you any of them??If so please send the code how to take control of labels inside the grdivew.
0
 

Author Comment

by:MRManthani
ID: 22597944
Can I use any of them OnRowCommand/OnRowCreated??
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

by:johnaryan
ID: 22599590
They are both used slightly differently.
OnRowCommand is used when a command button is used to update the row. The OnrowCreated fires when a new row is added.
Here's a goog article on how and when to use both:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowcreated.aspx

As long as you have the given the Labels id's in the row, you be able to reference them using code like:
Label label = (Label)e.Row.FindControl("myLabel");

0
 

Author Comment

by:MRManthani
ID: 22603598
Now how should i proceed to perform calculations in the column and get the result in the footer row.
0
 
LVL 5

Accepted Solution

by:
johnaryan earned 500 total points
ID: 22603813
You can add the footer row to the table definition and then call a function to return the calculated totals:
Your OnRowCreated can can record the total in a Property and then the call to GetTotal() will return that Property value.

Reference:
http://aspalliance.com/782_CodeSnip_How_to_Display_Sum_Total_in_the_Footer_of_the_GridView_Control
<asp:GridView ID="GridView1"

 ...

<Columns>

...

<FooterTemplate>

  <%# GetTotal().ToString() %>

</FooterTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DLL in ASP.NET 20 45
asp.net bundle 8 36
Windows Service to Receive TCP Packets 4 50
Align Buttons next to each other 2 14
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

11 Experts available now in Live!

Get 1:1 Help Now