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(ob ject 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("LabelTo talHardwar eCost") as Label;
TotalHWCostref.Text = "$"+TotalHWCost.ToString() ;
}
}
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(ob
{
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[
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
Label TotalHWCostref = e.Row.FindControl("LabelTo
TotalHWCostref.Text = "$"+TotalHWCost.ToString()
}
}
There is an OnRowAdded event that you could use....
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.
ASKER
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");
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("
ASKER
Now how should i proceed to perform calculations in the column and get the result in the footer row.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.