<asp:GridView ID="gvBasket" runat="server" AutoGenerateColumns="False"> <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" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#003399" /> </asp:GridView>
protected void Delete_Click(object sender, EventArgs e) { if (!Page.IsPostBack) { Button btn = (Button)sender; int id = int.Parse(btn.CommandArgument); string Query = "DELETE FROM ShoppingBasket WHERE Date IN (SELECT TOP 1 Date FROM shoppingBasket WHERE ProductID = " + id + " AND UserID = '" + (string)Session["UserName"] + "' ORDER BY Date DESC)"; ConnectionHandler objHandler = new ConnectionHandler(); DataTable dt = objHandler.ExecuteSelect(Query); } }
Page EnableEventValidation="false"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)