By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Deleting a row in gridview

P: 4
I have a gridview with a delete command...

I really need to delete items by 'Product ID', instead of 'SessionID' - that is displayed in the code below...

I have tried: " DeleteCommand="DELETE * FROM [Basket] WHERE [SessionID] = ?" "... but it does not delete any of the records, just refreshes the gridview... Any help would be greatly appreciated.
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
  2.                                         BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
  3.                                         CellPadding="4" CellSpacing="2" DataKeyNames="SessionID"
  4.                                         DataSourceID="AccessDataSource1" RowDataBound="GridView2_DataBound"
  5.                                         EmptyDataText="There are currently no items in your basket." Font-Bold="True"
  6.                                         Font-Names="Cambria" Font-Size="Medium" ForeColor="Black"
  7.                                         style="font-family: Cambria; font-size: medium">
  8.                                         <Columns>
  9.                                             <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/x.jpg"
  10.                                                 DeleteText="Remove" ShowDeleteButton="True" />
  11.                                             <asp:BoundField DataField="SessionID" HeaderText="SessionID" ReadOnly="True"
  12.                                                 SortExpression="SessionID" Visible="False" />
  13.                                             <asp:BoundField DataField="ProductID" HeaderText="Offer #"
  14.                                                 SortExpression="ProductID" />
  15.                                             <asp:BoundField DataField="ProductName" HeaderText="Name"
  16.                                                 SortExpression="ProductName" />
  17.                                             <asp:BoundField DataField="ProductPrice" HeaderText="Price"
  18.                                                 SortExpression="ProductPrice" DataFormatString="{0:C}" />
  19.                                         </Columns>
  20.                                         <FooterStyle BackColor="#CCCCCC" />
  21.                                         <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  22.                                         <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
  23.                                         <RowStyle BackColor="White" />
  24.                                         <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  25.                                         <SortedAscendingCellStyle BackColor="#F1F1F1" />
  26.                                         <SortedAscendingHeaderStyle BackColor="Gray" />
  27.                                         <SortedDescendingCellStyle BackColor="#CAC9C9" />
  28.                                         <SortedDescendingHeaderStyle BackColor="#383838" />
  29.                                     </asp:GridView>
  30.                                     <asp:AccessDataSource ID="AccessDataSource1" runat="server"
  31.                                         DataFile="~/Db1.accdb"
  32.                                         SelectCommand="SELECT * FROM [Basket] WHERE ([SessionID] = ?)"
  33.                                         InsertCommand="INSERT INTO [Basket] ([SessionID], [ProductID], [ProductName], [ProductPrice]) VALUES (?, ?, ?, ?)"
  34.                                         DeleteCommand="DELETE * FROM [Basket] WHERE [SessionID] = ?">
  35.                                         <InsertParameters>
  36.                                             <asp:Parameter Name="SessionID" Type="String" />
  37.                                             <asp:Parameter Name="ProductID" Type="Int32" />
  38.                                             <asp:Parameter Name="ProductName" Type="String" />
  39.                                             <asp:Parameter Name="ProductPrice" Type="Decimal" />
  40.                                         </InsertParameters>
  41.                                         <SelectParameters>
  42.                                             <asp:ControlParameter ControlID="LabelSesh" Name="SessionID"
  43.                                                 PropertyName="Text" Type="String" />
  44.                                         </SelectParameters>
Apr 8 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.