Link to home
Start Free TrialLog in
Avatar of Lorna70
Lorna70

asked on

GridView - assigning a value to a control after GridView is rendered

I have a Gridview (see attached code) which displays records from DB for each day.  The first few records (rows) could be for Monday and then the next few for Tuesday etc etc.  In the Template field I have a Label control (lblSubTotalPrice) which needs to display a total for each day so basically I only want that label to display a total once for each day.  So there could be 5 rows of amounts for Monday but I only want to display the total once for those 5 rows (i.e for a Monday) and then the same for each subsequent day.  I thought I could do this on OnRowDataBound but I would need to check each record and when the record changed from Monday to Tuesday, I would need to go back to the previous record and put the total for Monday in – this is not possible on OnRowDataBound.  Therefore, I think I need a solution where I can set the value of lblSubTotalPrice for each day AFTER the GridView is rendered.  I’m open to other solutions though – e.g maybe I should be constructing a complex SQL statement so I can do this on OnRowDataBound??
EE-problem.txt
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America 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
Avatar of Lorna70
Lorna70

ASKER

Thanks - looked at the code but I'll need to check when Monday changes to Tuesday and at that point, add Monday's total to the previous row.  Can I do -1 instead of +1 at the following point?:

//Add the row at the end of the list, but before the footer.
        tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1, row);
Yes. Rows.AddAt will add the row wherever you tell it to.
Avatar of Lorna70

ASKER

Great thanks very much - all working now :-)