dblayout
|
| Posted: 08/09/2003, 2:56 PM |
|
I am doing a query on table. 2 of the field sare dollar amounts. I am only showing 10 records at a time but I need to show the sum of each of these columns from all records returned from the query. What is the best way to handle this in CCS?
Thanks
Chris
|
|
|
 |
glerma
|
| Posted: 08/09/2003, 3:24 PM |
|
Dude. Try reading the CCS Help Manual sometime...
From CCS Help
************************************************
--------------------------------------------------------------------------------
Simple Report with Total
This example shows how to create a simple report with a Total row at the bottom of the grid. The Grid has a column for the Employee name and another for the number of hours spent by the employee. The bottom row sums up the spent hours for all the employees listed in the grid. Employee Spent Hours
John Smith 10
Rob McDonald 20
Bob Kuch 15
Total: 45
Switch to HTML mode and add the HTML code in blue below the Row block.
<!-- BEGIN Row -->
<tr>
<td class="ClearDataTD">{Employee}</td>
<td class="ClearDataTD">{SpentHours}</td>
</tr>
<!-- END Row -->
<tr>
<td class="ClearDataTD"><b>Total</b></td>
<td class="ClearDataTD"></td>
</tr>
Add a Summ Label control into the last cell of the added code. ( Note that we use 'Summ' and not 'Sum' because 'Sum' is a reserved word in some of the languages including SQL).
<!-- BEGIN Row -->
<tr>
<td class="ClearDataTD">{Employee}</td>
<td class="ClearDataTD">{SpentHours}</td>
</tr>
<!-- END Row -->
<tr>
<td class="ClearDataTD"><b>Total</b></td>
<td class="ClearDataTD">{Summ}</td>
</tr>
Set the Data Type property to Integer or Float for the SpentHours and Summ Label controls.
In the Before Show Row event of the grid, add the code below:
ASP
Function Employees_BeforeShowRow()
Employees.Summ.Value = Employees.Summ.Value + Employees.SpentHours.Value
End Function
PHP
function Employees_BeforeShowRow() {
global $Employees;
$Employees->Summ->SetValue($Employees->Summ->GetValue() + $Employees->SpentHours->GetValue() );
}
Perl
sub Employees_BeforeShowRow() {
$Employees->{Summ}->SetValue($Employees->{Summ}->GetValue() + $Employees->{SpentHours}->GetValue() );
}
Cold Fusion
<!---Employees_BeforeShowRow --->
<CFSET fldSumm=Val(fldSumm) + fldSpentHours>
Java
//Employees_BeforeShowRow
long summ = e.getGrid().getControl("Summ").getValue() == null ? 0 : Utils.convertToLong(e.getGrid().getControl("Summ").getValue()).longValue();
long spent = e.getGrid().getControl("SpentHours").getValue() == null ? 0 : Utils.convertToLong(e.getGrid().getControl("SpentHours").getValue()).longValue();
e.getGrid().getControl("Summ").setValue( summ + spent);
VB.Net
Add a variable called Summ below the 'End Forms Definition section.
'End Forms Definition
Dim Summ As Integer ' or Double
Add the Before Show Row event for the Grid.
'Employees_Summ_BeforeShow
EmployeesSumm.Text = Summ.ToString()
Add the Before Show event for the Summ Label.
'Employees_BeforeShowRow
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Summ += DataItem.SpentHours.Value
End If
C#
Add a variable called Summ below the 'End Forms Definition section.
//End Forms Definition
protected Int64 Summ;
Add the Before Show Row event for the Grid.
//Employees_Summ_BeforeShow
EmployeesSumm.Text = Summ.ToString();
Add the Before Show event for the Summ Label.
//Employees_BeforeShowRow
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
Summ += (Int64)(DataItem.SpentHours.Value);
}
See also:
Before Show Row event, Grid form, Label control
************************************************
Regards,
george
|
|
|
 |
dblayout
|
| Posted: 08/11/2003, 8:10 AM |
|
Thanks for the answer. I won't dignify your first comment with a response.
Thanks just the same.
|
|
|
 |
|