Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C#

Posted on 2008-09-29
6
Medium Priority
?
217 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 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