Here is my code:
<asp:GridView ID="gvBasket" runat="server" AutoGenerateColumns="False"
ShowFooter="True">
<FooterStyle Font-Bold="true" BackColor="#61A6F8" ForeColor="black" />
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" />
<asp:BoundField DataField="qty" HeaderText="Quantity" SortExpression="qty" />
<asp:BoundField DataField="UnitPrice" HeaderText="Unit Prce" SortExpression="unitPrice"
HtmlEncode="false" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="Total" SortExpression="Total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text='<%# Eval("Total", "{0:c}") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblsubTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sessionID" HeaderText="Session"
SortExpression="sessionID" visible="false"/>
<asp:BoundField DataField="UserID" HeaderText="user" SortExpression="UserID" Visible="false" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
SortExpression="ProductID" visible="false"/>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="Delete" runat="server"
CommandArgument='<%# Bind("productID") %>' onclick="Delete_Click"
Text="Delete" CommandName="DeleteItem" />
<asp:Button ID="btnAdd" runat="server"
CommandArgument='<%# Bind("productID") %>' CommandName="AddItem"
onclick="btnAdd_Click" Text="Add" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and code behind is:
decimal stotal = 0;
protected void gvBasket_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblTotal = (Label)e.Row.FindControl("lblTotal");
decimal Total = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Total"));
lblTotal.Text = Total.ToString("c");
sTotal += Total;
}
if (e.Row.RowType == DataControlRowType.Footer)
{ Label lblsubTotal = (Label)e.Row.FindControl("lblsubTotal");
lblsubTotal.Text = sTotal.ToString("c");
}}
I want the total Total column to have a subtotal at the bottom.
my code for the table is:
string session = Session.SessionID.ToString();
string Query = "SELECT tblProduct.ProductName as ProductName, tblProduct.UnitPrice as UnitPrice, sum(ShoppingBasket.qty) as Qty , tblProduct.UnitPrice*sum(ShoppingBasket.qty) as Total, ShoppingBasket.sessionID, ShoppingBasket.userID, ShoppingBasket.productID FROM ShoppingBasket join tblProduct on ShoppingBasket.productID=tblProduct.ProductID where ShoppingBasket.sessionID= '" + session + "' AND ShoppingBasket.UserID='' group by ShoppingBasket.userID, tblProduct.ProductName, tblProduct.UnitPrice, ShoppingBasket.sessionID, ShoppingBasket.productID";
ConnectionHandler objHandler = new ConnectionHandler();
DataTable dt = objHandler.ExecuteSelect(Query);
gvBasket.DataSource = dt;
gvBasket.DataBind();
I have code in a DAL if this is needed please ask.

New Topic/Question
Reply



MultiQuote





|