2013-01-14 25 views
0

我想要做的是在最後一行中得到總和。這裏有2組itens與總和的例子:SumTotal在每組結束時經典asp

我:

1000 (group number) 

TitleUm TitleTres TitleQuatro 
Apple  1   20 
Pear  5   12 

1001 (group number) 

TV  1   20 
Mobile 1   12 
Car  1   15 
Bicycle 1   5 

TOTAL 10   84 

我要找:

1000 (group number) 

TitleUm TitleTres TitleQuatro 
Apple  1   20 
Pear  5   12 

TOTAL 6   32 

1001 (group number) 

TV  1   20 
Mobile 1   12 
Car  1   15 
Bicycle 1   5 

TOTAL 4   52 

代碼波紋管做幾乎所有的東西,列出項目,每行每一個值,但它現在展示的總和:

<table class="Itens"> 
<% 
currentGroupName = "" 
previousGroupName = "" 
Do Until ItensList.EOF 
currentGroupName = ItensList("oito") 
Um= ItensList("um") 
Tres= ItensList("tres") 
Quatro= CCur(ItensList("quatro")) 

If currentGroupName <> previousGroupName Then 
%> 

<tr> 
<td><% Response.Write currentGroupName %></td> 
</tr> 
<tr>    
<th><% Response.Write TituloUm %></th> 
<th><% Response.Write TituloTres %></th> 
<th><% Response.Write TituloQuatro %></th> 
</tr> 

<% 
End If 
%> 

<% 
Um= CCur(ItensList("um")) 
Tres= CCur(ItensList("tres")) 
Quatro= CCur(ItensList("quatro")) 
%> 

<tr> 
<td><% Response.Write Um %></td> 
<td><% Response.Write Tres %></td> 
<td><% Response.Write Quatro %></td> 
</tr> 

<% 
previousGroupName = currentGroupName 
ItensList.MoveNext 
Loop 
ItensList.Close 
%> 

<tr class="Total"> 
<td>TOTAL</td> 
<td><% Response.Write ShowSumTotalTresHere %></td> 
<td><% Response.Write ShowSumTotalQuatroHere %></td> 
</tr> 
</table> 

感謝您的幫助

回答

0

每到一個變量添加像內環路這樣的:

<% 
SumSomething = 0 

Do Until objRs.EoF 
    SumSomething = SumSomething + objRs("SomeValue") 
objRs.MoveNext 
Loop 
%> 
... 
<tr> 
    <td><%= SumSomething%></td> 
... 
+0

謝謝,但原始代碼僅在組列表的末尾添加總行數,而不是在每個組中添加總行數(1 000 ... 1001 ...) – Khrys

0

你需要保持一個運行總計而你的循環,採取下面我舉的例子的代碼,我在循環之前宣佈了兩個新的增值經銷商:

Total_Tres   = 0 
Total_Quatro  = 0 

然後,我在你的循環incremement這些:

'Maintain Running Total 
Total_Tres   = Total_Tres + Tres 
Total_Quatro  = Total_Quatro + Quatro 

最後,輸出的總增值經銷商:

<td>TOTAL</td> 
<td><% = Total_Tres %></td> 
<td><% = Total_Quatro %></td> 

完整的例子(未經測試)

<table class="Itens"> 
<% 
currentGroupName = "" 
previousGroupName = "" 
Total_Tres   = 0 
Total_Quatro  = 0 
Do Until ItensList.EOF 
    currentGroupName = ItensList("oito") 
    Um     = ItensList("um") 
    Tres    = ItensList("tres") 
    Quatro    = CCur(ItensList("quatro")) 

    If currentGroupName <> previousGroupName Then 
     %> 
     <tr> 
      <td><% = currentGroupName %></td> 
     </tr> 
     <tr>    
      <th><% = TituloUm %></th> 
      <th><% = TituloTres %></th> 
      <th><% = TituloQuatro %></th> 
     </tr> 
     <% 
    End If 

    Um  = CCur(ItensList("um")) 
    Tres = CCur(ItensList("tres")) 
    Quatro = CCur(ItensList("quatro")) 
    %> 
    <tr> 
     <td><% = Um %></td> 
     <td><% = Tres %></td> 
     <td><% = Quatro %></td> 
    </tr> 
    <% 
    '#### Maintain Running Total 
    Total_Tres   = Total_Tres + Tres 
    Total_Quatro  = Total_Quatro + Quatro 

    '### Flag current group 
    previousGroupName = currentGroupName 
    ItensList.MoveNext 
Loop 
ItensList.Close 
%> 
<tr class="Total"> 
<td>TOTAL</td> 
<td><% = Total_Tres %></td> 
<td><% = Total_Quatro %></td> 
</tr> 
</table> 
+0

謝謝,但這將保持總線只在最後的組中,而不是每組總線。 – Khrys

+0

@Khrys我只是在展示這個概念,你所需要做的就是在組更改時打印總數,然後將運行總數重置爲0--如果您仍然不明白,請告訴我,我將編輯我的答案。 – HeavenCore

+0

我試着做你說的,但沒有成功......你能告訴我嗎?感謝很多 – Khrys