Gridview Delete not Deleting

I am trying to use a command button to delete a row from a gridview. When I click the command button though, the page posts but my record is still there... no errors, just nothing seems to happen. Below is what I think is the relevant code, let me know if you need to see anything else.

 I'm kinda new to working with gridview objects, it would be nice if I could see what SQL command is acctually ran... maybe there are other things I can check too, I'm just not sure how.

 

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
        AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
        BorderWidth="1px" CellPadding="4" DataSourceID="cnnToolbar" ForeColor="Black"
        GridLines="Vertical" PageSize="50" Width="100%"
 >

 <Columns>
  <asp:BoundField DataField="FunctionID" HeaderText="FunctionID" InsertVisible="False" ReadOnly="True" SortExpression="FunctionID" Visible="False" />

  <asp:CommandField HeaderText="Action" ShowCancelButton="False" ShowDeleteButton="True">
         <ItemStyle HorizontalAlign="Center" />
  </asp:CommandField>

 </Columns>
</asp:GridView>


<asp:SqlDataSource ID="cnnToolbar" runat="server" ConnectionString="<%$ ConnectionStrings:CMDB2ConnectionString %>"
        DeleteCommand="DELETE FROM dbo.Toolbar WHERE (FunctionID = @FunctionID)"
 >
     
 <DeleteParameters>
 <asp:Parameter Name="FunctionID" />
 </DeleteParameters>

</asp:SqlDataSource>


http://www.krissteele.net - http://www.steeleits.com - http://www.evilscale.com - http://www.starcraftlive.net
0
Kriswd40
10/11/2007 2:44:14 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
820 Views

Similar Articles

[PageSpeed] 25

You need to add your Database field to your GridView's DataKeys property for UPDATING and DELETING data with SQL. Set your DataKeys to FunctionID and it should work perfectly.


If you get an answer to your question, please mark it as 'Answer' Smile


www.lymanlax.com | www.possumslax.com
0
apollolax123
10/11/2007 2:52:59 PM
0
Kriswd40
10/11/2007 3:07:04 PM

I have this problem too, and it was NOT fixed by setting the DataKeyNames property of the gridview.  The DeleteQuery on the data source for my gridview is:

 DELETE FROM dbo.bhp_servicecostentry WHERE (servicecostentryid = @Pid)

The servicecostentryid field is definitely part of the data displayed in the grid

I note that in the Commands and Parameters editor, the source for the parameter Pid above is "None".  I tried setting it to the gridview's SelectedValue property, but that didn't change anything either.  Any idea what else it can be?  I have a lot of gridviews in my app that will not delete records!


Steve Marshall
0
marshallartsoz
12/6/2007 2:25:50 AM
Reply: