?
Solved

Gridview showing sum of rows in one row

Posted on 2007-11-18
1
Medium Priority
?
1,880 Views
Last Modified: 2008-02-01
Hello, I have a gridview populated by the following sql query: When I run the query, I get the error that there is no row.datarow for "Amount". I think it is because I am using a "SUM" function in the sql query. I need to know how to structure the gridview to display the sumed amounts from columns "amount" and "amountbilled". Thank you:


SqlDataSource2.SelectCommand = "SELECT Billing.InvoiceID, Billing.OrdersID, Billing.ClientID, SUM(Billing.Amount), SUM(Billing.AmountPaid), Client.ClientID, Company.CompanyID, Client.ClientFirmName, Company.CompanyName, Client.ClientAddress, Company.CompanyAddress, Client.ClientCity, Company.CompanyCity, Client.ClientState, Company.CompanyState FROM Billing Left Outer Join Client ON ((Billing.ClientID = Client.ClientID) and (BillClient = 1)) Left Outer Join Company ON ((Billing.ClientID = Company.CompanyID) and (Billing.BillClient = 0)) Group by Billing.InvoiceID, Billing.OrdersID, Billing.ClientID, Client.ClientID, Company.CompanyID, Client.ClientFirmName, Company.CompanyName, Client.ClientAddress, Company.CompanyAddress, Client.ClientCity, Company.CompanyCity, Client.ClientState, Company.CompanyState"

My gridview code is:

</asp:GridView>
                        <asp:GridView id="GridView2" runat="server" ShowFooter="true" BackColor="White" AllowSorting="True" AutoGenerateColumns="False" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataKeyNames="InvoiceID" DataSourceID="SqlDataSource2" GridLines="None" Width="864px">
                    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                    <Columns>
                       
                        <asp:TemplateField HeaderText="Client/Company Name" SortExpression="ClientID">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox35211" runat="server" Text='<%# Bind("ClientID") %>'></asp:TextBox>
                                <asp:TextBox ID="TextBox22511" runat="server" Text='<%# Bind("CompanyID") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:hyperlink ID="Label5234241" NavigateUrl='<%# Eval("clientID", "ClientAdminEdit.aspx?clientNumber={0}&type=" + Request.QueryString("type")) %>' runat="server" Text='<%# Bind("ClientFirmName") %>'></asp:hyperlink>
                                <asp:hyperlink ID="Label5523421" NavigateUrl='<%# Eval("companyID", "CompanyAdminEdit.aspx?companyNumber={0}&type=" + Request.QueryString("type")) %>' runat="server" Text='<%# Bind("CompanyName") %>'></asp:hyperlink>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Address" SortExpression="ClientAddress">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox41" runat="server" Text='<%# Bind("ClientAddress") %>'></asp:TextBox>
                                <asp:TextBox ID="TextBox441" runat="server" Text='<%# Bind("CompanyAddress") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label51" runat="server" Text='<%# Bind("ClientAddress") %>'></asp:Label>
                                <asp:Label ID="Label551" runat="server" Text='<%# Bind("CompanyAddress") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="City" SortExpression="ClientCity">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox51" runat="server" Text='<%# Bind("ClientCity") %>'></asp:TextBox>
                                <asp:TextBox ID="TextBox541" runat="server" Text='<%# Bind("CompanyCity") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label61" runat="server" Text='<%# Bind("ClientCity") %>'></asp:Label>
                                <asp:Label ID="Label621" runat="server" Text='<%# Bind("CompanyCity") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="State" SortExpression="ClientState">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox61" runat="server" Text='<%# Bind("ClientState") %>'></asp:TextBox>
                                <asp:TextBox ID="TextBox651" runat="server" Text='<%# Bind("CompanyState") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label711" runat="server" Text='<%# Bind("ClientState") %>'></asp:Label>
                                <asp:Label ID="Label731" runat="server" Text='<%# Bind("CompanyState") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Amount Billed" SortExpression="Amount">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox3631" runat="server" Text='<%# Bind("Amount") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label36771" runat="server" Text='<%# Bind("Amount") %>'></asp:Label>
                            </ItemTemplate>
                           
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Amount Paid" SortExpression="AmountPaid">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox9331" runat="server" Text='<%# Bind("AmountPaid") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1321" runat="server" Text='<%# Bind("AmountPaid") %>'></asp:Label>
                            </ItemTemplate>
                           
                        </asp:TemplateField>                        
                                 
                        <asp:HyperLinkField HeaderText="Order #" DataTextField="OrdersID" DataNavigateUrlFields="OrdersID"  DataNavigateUrlFormatString="Control_Page_Copy2.aspx?NewJobNumber={0}"/>
                       
                       
                    </Columns>
                    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                </asp:GridView>
0
Comment
Question by:mlg101
1 Comment
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 20310340
SUM(Billing.AmountPaid) as Amount   , Make this change

SqlDataSource2.SelectCommand = "SELECT Billing.InvoiceID, Billing.OrdersID, Billing.ClientID, SUM(Billing.Amount), SUM(Billing.AmountPaid) as Amount, Client.ClientID, Company.CompanyID, Client.ClientFirmName, Company.CompanyName, Client.ClientAddress, Company.CompanyAddress, Client.ClientCity, Company.CompanyCity, Client.ClientState, Company.CompanyState FROM Billing Left Outer Join Client ON ((Billing.ClientID = Client.ClientID) and (BillClient = 1)) Left Outer Join Company ON ((Billing.ClientID = Company.CompanyID) and (Billing.BillClient = 0)) Group by Billing.InvoiceID, Billing.OrdersID, Billing.ClientID, Client.ClientID, Company.CompanyID, Client.ClientFirmName, Company.CompanyName, Client.ClientAddress, Company.CompanyAddress, Client.ClientCity, Company.CompanyCity, Client.ClientState, Company.CompanyState"
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question