我希望为每个位置添加一行,如下图所示。该行将显示每列的总计。我已经计算了这些值(<%= owetotal%>,<%= paidtotal%>,<%= origtotal%>)只需要将它们放在正确的位置,我似乎无法格式化就像我想要的那样。
目前它看起来像这样:
我希望它看起来像这样:
我的ASPX页面
<form id="form1" runat="server">
<div class="container">
<div class="page-header">
<h1>
Report</h1>
<br />
<div class="row">
<div class="span11">
<%
System.Data.OleDb.OleDbConnection pcn;
System.Data.OleDb.OleDbCommand pcm;
System.Data.OleDb.OleDbDataReader prs;
pcn = new System.Data.OleDb.OleDbConnection("");
pcm = new System.Data.OleDb.OleDbCommand();
pcn.Open();
pcm.Connection = pcn;
var tableSql = @"SELECT * FROM Accounts";
pcm.CommandText = tableSql;
prs = pcm.ExecuteReader();
var rowcount = 0;
var CurrentLocation = "";
while (prs.Read())
{
rowcount++;
%>
<% if (prs["Location"].ToString() != CurrentLocation)
{ %>
<table width="100%" class="table">
<thead>
<tr>
<th>
Name
</th>
<th>
Owes
</th>
<th>
Paid
</th>
<th>
Original Amt
</th>
<th>
Date
</th>
</tr>
</thead>
<h4>
<%= prs["Location"].ToString()%></h4>
<%
CurrentBranch = prs["Loction"].ToString();
} %>
<tr>
<td>
<%= prs["Name"].ToString() %>
</td>
<td>
$<%= prs["Owes"].ToString() %>
</td>
<td>
$<%= prs["Paid"].ToString() %>
</td>
<td>
$<%= prs["OrigAmt"].ToString() %>
</td>
<td>
<%= Convert.ToDateTime(prs["SubmitDate"].ToString()).ToShortDateString() %>
</td>
</tr>
<%
}
prs.Close();
pcn.Close();
%>
</table>
</div>
</div>
</div>
</div>
</form>
答案 0 :(得分:0)
在SQL语句中,添加
UNION SELECT 'Totals', sum(Owes), sum (Paid), sum(OrigAmt), '' FROM Accounts
答案 1 :(得分:0)
您可以在控制器的Page_Load处理程序中执行此操作。向每个表添加新行并将其放在总计值中。写下关于这个问题:
foreach(var column in table.Columns)
{
foreach(var field in column)
{
//check if it isn't last row
//write the sum of (0..n-1) fields to lsat field in column
}
}