0
我有一個GridView,它顯示了我公司中每個部門的每個測驗的參與者總數。我現在想要的是總結這些數字,並添加一個新行以顯示每個測驗後所有分部的參與者總數(即每個測驗有小計)。 那麼該怎麼做?如何在此(彙總表)GridView中的每個測驗後顯示總數?
我的ASP.NET代碼:
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource6" CssClass="datatable"
CellPadding="0" BorderWidth="0px" GridLines="None"
OnDataBinding="GridView3_DataBinding" OnRowDataBound="GridView3_RowDataBound" AllowPaging="True" PageSize="16">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Quiz"
SortExpression="Title" />
<asp:BoundField DataField="DivisionShortcut"
HeaderText="Division"
SortExpression="DivisionShortcut" />
<asp:BoundField DataField="Total Number of Participants"
HeaderText="Total Number of Participants" ReadOnly="True"
SortExpression="Total Number of Participants"/>
</Columns>
<RowStyle CssClass="row" />
<SortedAscendingCellStyle CssClass="sortasc"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle CssClass="sortasc"></SortedAscendingHeaderStyle>
<SortedDescendingHeaderStyle CssClass="sortdesc"></SortedDescendingHeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT dbo.Quiz.Title, dbo.Divisions.DivisionShortcut, COUNT(DISTINCT dbo.UserQuiz.Username) AS [Total Number of Participants]
FROM dbo.employee INNER JOIN
dbo.UserQuiz ON dbo.employee.Username = dbo.UserQuiz.Username INNER JOIN
dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID INNER JOIN
dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode
GROUP BY dbo.Quiz.Title, dbo.Divisions.DivisionShortcut
ORDER BY dbo.Quiz.Title"></asp:SqlDataSource>
我的代碼隱藏:
protected void GridView3_DataBinding(object sender, EventArgs e)
{
GridViewGroup first = new GridViewGroup(GridView3, null, "Title");
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
//for adding a spearator between rows
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowIndex % 7) == 0)
{
foreach (TableCell c in e.Row.Cells)
c.Attributes.Add("Style", "border-top: #BBD9EE 5px double ");
}
}
}
一個當前表的快照:
如何找到總數?我的數據庫中沒有這個號碼。 – 2012-03-04 04:57:10
您將必須計算GetTotal()方法中的總數。 – Bracke 2012-03-16 13:02:00