Link to home
Start Free TrialLog in
Avatar of MRManthani
MRManthani

asked on

C#

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();
        }

    }
Avatar of johnaryan
johnaryan
Flag of Ireland image

There is an OnRowAdded event that you could use....
Avatar of MRManthani
MRManthani

ASKER

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.
Can I use any of them OnRowCommand/OnRowCreated??
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");

Now how should i proceed to perform calculations in the column and get the result in the footer row.
ASKER CERTIFIED SOLUTION
Avatar of johnaryan
johnaryan
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial