0

我希望为每个位置添加一行,如下图所示。该行将显示每列的总数。我已经计算了这些值( <%= 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>
4

2 回答 2

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
    }
}
于 2013-05-29T16:39:13.657 回答
0

在您的 SQL 语句中,添加

UNION SELECT 'Totals', sum(Owes), sum (Paid), sum(OrigAmt), '' FROM Accounts
于 2013-05-29T16:33:46.747 回答