ewhitmor Posted September 8, 2006 Share Posted September 8, 2006 Hi all,I am in the beginning stages of learning asp.net and have a question about GridView. I have data that i am trying to display. I am able to display it without problem but i want to total a couple columns in the footer area below the columns. Everything i have read has me doing a bunch of wierd work arounds. Here is what i got so far: <%@ Page Language="VB" %><%@ Import Namespace="System.Data" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml" ><head> <title>enVision Utilities Web</title></head><body> <form runat="server"> <asp:GridView ID="GridView1" runat="server" DataSourceID="enVisionData" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" RowStyle-Font-Size="9" AllowSorting="false" ShowFooter = "true" RowStyle-Wrap = "false" > <HeaderStyle BackColor="DarkGreen" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#fbf6e0" ForeColor="Black" HorizontalAlign="Center" /> <AlternatingRowStyle BackColor="White" ForeColor="Black"/> <FooterStyle BackColor="#fbf6e0" /> <Columns> <asp:BoundField DataField="Carrier" SortExpression="Carrier" HeaderText="Carrier" ItemStyle-HorizontalAlign="center" /> <asp:BoundField DataField="ProNumber" SortExpression="ProNumber" HeaderText="ProNumber" /> <asp:BoundField DataField="ShipDate" SortExpression="ShipDate" HeaderText="ShipDate" ItemStyle-HorizontalAlign="center" HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" /> <asp:BoundField DataField="Shipper" SortExpression="Shipper" HeaderText="Shipper" ItemStyle-HorizontalAlign="center" /> <asp:BoundField DataField="SCity" SortExpression="SCity" HeaderText="SCity" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="SSt" SortExpression="SSt" HeaderText="SSt" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="Consignee" SortExpression="Consignee" HeaderText="Consignee" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="CCity" SortExpression="CCity" HeaderText="CCity" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="CSt" SortExpression="CSt" HeaderText="CSt" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="Mode" SortExpression="Mode" HeaderText="Mode" ItemStyle-HorizontalAlign="center"/> <asp:BoundField DataField="Weight" SortExpression="Weight" HeaderText="Weight" HtmlEncode="false" ItemStyle-HorizontalAlign="right" DataFormatString="{0:#,###}" /> <asp:BoundField DataField="Net" SortExpression="Net" HeaderText="Net" HtmlEncode="false" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="right" /> <asp:BoundField DataField="Accessorial" SortExpression="Accessorial" HeaderText="Accessorial" HtmlEncode="false" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="right"/> <asp:BoundField DataField="FS" SortExpression="FS" HeaderText="FS" HtmlEncode="false" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="right"/> <asp:BoundField DataField="Disc" SortExpression="Disc" HeaderText="Disc" HtmlEncode="false" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="right"/> <asp:BoundField DataField="AmtPaid" SortExpression="AmtPaid" HeaderText="AmtPaid" HtmlEncode="false" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="right"/> </Columns> </asp:GridView> <asp:SqlDataSource ID="enVisionData" runat="server" ConnectionString="Data Source=XXX.XXX.XXX.XXX;Initial Catalog=enVisionDataSQL;Persist Security Info=True;User ID=XXXXXXXXXX;PWD=XXXXXXXXX" SelectCommand="sp_eric_ole_data" SelectCommandType="StoredProcedure" > <SelectParameters> <asp:Parameter DefaultValue="9/1/2006" Name="StrDate" Type="DateTime" /> <asp:Parameter DefaultValue="9/15/2006" Name="EndDate" Type="DateTime" /> <asp:Parameter DefaultValue="<ROOT><Client ClientID='2'/></ROOT>" Name="ClientIDs" Type="String" /> </SelectParameters> </asp:SqlDataSource> </form></body></html> This website gives you an idea of what i am trying to do: Example PageThanks for your help,Eric Link to comment Share on other sites More sharing options...
ewhitmor Posted September 8, 2006 Author Share Posted September 8, 2006 I figured it out but i still think M$ needs to make this easier in thier next version of ASP.Net.Here is how i did it. Dim total_amtpaid As Decimal Dim total_disc As Decimal Dim total_fs As Decimal Dim total_assl As Decimal Dim total_Net As Decimal Dim total_Weight As Decimal Protected Sub TotIncurGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 'Sum Columns If e.Row.RowType = DataControlRowType.DataRow Then total_Weight += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Weight")) total_Net += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Net")) total_assl += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Accessorial")) total_fs += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "FS")) total_disc += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Disc")) total_amtpaid += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "AmtPaid")) ElseIf e.Row.RowType = DataControlRowType.Footer Then e.Row.Cells(9).Text = "<strong>Totals:</strong>" ' for the Footer, display the running totals e.Row.Cells(10).Text = total_Weight.ToString("n0") e.Row.Cells(11).Text = total_Net.ToString("c") e.Row.Cells(12).Text = total_assl.ToString("c") e.Row.Cells(13).Text = total_fs.ToString("c") e.Row.Cells(14).Text = total_disc.ToString("c") e.Row.Cells(15).Text = total_amtpaid.ToString("c") e.Row.HorizontalAlign = HorizontalAlign.Right e.Row.Font.Bold = False e.Row.Font.Size = 9 End If End Sub Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now