グリッドビューに追加されたすべての製品の価格と数量を合計しようとしていますが、フッターに合計が表示されない理由がわかりません。私がvb用に持っているコードは、数量に価格を掛けて、グリッドビューのフッターに入れる必要があります。グリッドビューのフッターが表示されているので、それが問題ではないことがわかります。任意の助けをいただければ幸いです。
asp:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="Cart" AllowSorting="True" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" ShowFooter="True" AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True" DataKeyNames="cartID">
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:BoundField DataField="cartID" HeaderText="cartID" SortExpression="cartID"
InsertVisible="False" ReadOnly="True" Visible="False"></asp:BoundField>
<asp:BoundField DataField="cartNO" HeaderText="cartNO" SortExpression="cartNO"
Visible="False" />
<asp:BoundField DataField="productID" HeaderText="productID"
SortExpression="productID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="productName" HeaderText="productName"
SortExpression="productName" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="price" HeaderText="price"
SortExpression="price" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="quantity" HeaderText="quantity"
SortExpression="quantity" />
<asp:TemplateField HeaderText="SubTotal" SortExpression="subTotal" >
<ItemTemplate>
<%# Eval("price") * Eval("quantity")%>
</ItemTemplate>
<%-- <FooterTemplate>
<asp:Label ID="sum" runat="server"/>
</FooterTemplate>--%>
</asp:TemplateField>
VB パブリック クラス MyCart
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strcartNO As String = ""
Dim cookieBack As HttpCookie
cookieBack = HttpContext.Current.Request.Cookies("cartNO")
strcartNO = cookieBack.Value
'sqldscartLine.selectCommand = "Select * from cartLine where cartNO = '" & strcartNO & "'"
GridView1.DataBind()
End Sub
Public Shared Sub DeleteMethod(ByVal original_OrderID As Integer, _
ByVal original_ProductID As Integer)
End Sub
Dim priceTotal As Decimal = 0
Dim quantityTotal As Integer = 0
Sub GridView1_RowDataBound(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' add the UnitPrice and QuantityTotal to the running total variables
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _
"price"))
quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, _
"quantity"))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(2).Text = "Totals:"
' for the Footer, display the running totals
e.Row.Cells(3).Text = priceTotal.ToString("c")
e.Row.Cells(4).Text = quantityTotal.ToString("d")
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End Sub