Here is the code for the gridview:
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
- BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
- CellPadding="4" CellSpacing="2" DataKeyNames="SessionID"
- DataSourceID="AccessDataSource1" OnRowDataBound="GridView2_RowDataBound"
- EmptyDataText="There are currently no items in your basket." Font-Bold="True"
- Font-Names="Cambria" Font-Size="Medium" ForeColor="Black" ShowFooter="True"
- style="font-family: Cambria; font-size: medium">
- <Columns>
- <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/x.jpg"
- DeleteText="Remove" ShowDeleteButton="True" />
- <asp:BoundField DataField="SessionID" HeaderText="SessionID" ReadOnly="True"
- SortExpression="SessionID" Visible="False" />
- <asp:BoundField DataField="ProductID" HeaderText="ProductID"
- SortExpression="ProductID" />
- <asp:BoundField DataField="ProductName" HeaderText="ProductName"
- SortExpression="ProductName" />
- <asp:BoundField DataField="ProductPrice" HeaderText="ProductPrice"
- SortExpression="ProductPrice" />
- </Columns>
- <FooterStyle BackColor="#CCCCCC" />
- <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
- <RowStyle BackColor="White" />
- <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
- <SortedAscendingCellStyle BackColor="#F1F1F1" />
- <SortedAscendingHeaderStyle BackColor="Gray" />
- <SortedDescendingCellStyle BackColor="#CAC9C9" />
- <SortedDescendingHeaderStyle BackColor="#383838" />
- </asp:GridView>
- <asp:AccessDataSource ID="AccessDataSource1" runat="server"
- DataFile="~/Db1.accdb"
- DeleteCommand="DELETE * FROM [Basket] WHERE [SessionID] = ?"
- SelectCommand="SELECT * FROM [Basket]">
- <DeleteParameters>
- <asp:Parameter Name="SessionID" Type="Int32" />
- </DeleteParameters>
- </asp:AccessDataSource>
Expand|Select|Wrap|Line Numbers
- Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
- Dim priceTotal As Decimal = 0
- 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, "ProductPrice"))
- ElseIf e.Row.RowType = DataControlRowType.Footer Then
- e.Row.Cells(3).Text = "Totals:"
- e.Row.Cells(4).Text = priceTotal.ToString("c")
- e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
- e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
- e.Row.Font.Bold = True
- End If
- End Sub