Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview Footer Total

Status
Not open for further replies.

Divaldo

Technical User
Sep 18, 2007
18
0
0
GB
Hi,

forgive me, but this is my first forray into asp.net.
I have a page with a gridview on that puls data from a SQL database and displays it. Basically, you select a user, aand/or faculty and it lists all the entries in the database relevant to them. One of the columns (TotalCost) is a monetary cost.

My Gridview has the footer displayed and I would like to be able to display a grand total of the 'TotalCost' column within the footer of my table.

Can anyone tell me whether this is possible, and how I would go about doing it?

Many thanks.

My page looks like this:

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h3>Reprographics Reporting</h3>
<div class="GridviewDiv">
<table style="width: 540px" border="0" cellpadding="0" cellspacing="1" class="GridviewTable">
<tr >

<td style="width: 130px;">
Department
</td>
<td style="width: 130px;">
User
</td>

</tr>
<tr >

<td style="width: 130px;">
<asp:DropDownList ID="ddldepartment" DataSourceID="dsPopulateDepartment" AutoPostBack="true"
DataValueField="FacultyName" runat="server" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>
<td style="width: 130px;">
<asp:DropDownList ID="ddluser" DataSourceID="dsPopulateUser" AutoPostBack="true"
DataValueField="ReproUser" runat="server" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>

</tr>
<tr>
<td colspan="5">
<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="true" DataSourceID="dsGridview" Width="540px" PageSize="10" CssClass="Gridview" ShowFooter="True">

<Columns>
<asp:BoundField DataField="ReproUser" HeaderText="User" SortExpression="FirstName"
ItemStyle-Width="120px" />
<asp:BoundField DataField="FacultyName" HeaderText="Faculty" SortExpression="FacultyName"
ItemStyle-Width="130px" />
<asp:BoundField DataField="TotalPrice" HeaderText="Cost" SortExpression="TotalPrice"
ItemStyle-Width="130px" />
<asp:TemplateField HeaderText="Total Price" SortExpression="Amount">
<ItemTemplate>
<asp:Literal ID="AmountLiteral" runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Literal ID="AmountTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>


</Columns>
</asp:GridView>
</td>
</tr>

</table>
</div>
<asp:SqlDataSource ID="dsGridview" runat="server" ConnectionString="<%$ ConnectionStrings:ReproDBConnection %>"
SelectCommand="SELECT * FROM Jobs" FilterExpression="FacultyName like '{0}%'
and ReproUser like '{1}%'">
<FilterParameters>
<asp:ControlParameter Name="FacultyName" ControlID="ddldepartment" PropertyName="SelectedValue" />
<asp:ControlParameter Name="ReproUser" ControlID="ddluser" PropertyName="SelectedValue" />

</FilterParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsPopulateDepartment" runat="server" ConnectionString="<%$ ConnectionStrings:ReproDBConnection %>"
SelectCommand="SELECT DISTINCT FacultyName from Jobs"></asp:SqlDataSource>
<asp:SqlDataSource ID="dsPopulateUser" runat="server" ConnectionString="<%$ ConnectionStrings:ReproDBConnection %>"
SelectCommand="SELECT DISTINCT ReproUser FROM Jobs order by ReproUser"></asp:SqlDataSource>
<asp:SqlDataSource ID="dsPopulatetotalprice" runat="server" ConnectionString="<%$ ConnectionStrings:ReproDBConnection %>"
SelectCommand="SELECT DISTINCT TotalPrice FROM Jobs"></asp:SqlDataSource>

</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top