468,720 Members | 1,737 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

Unable to delete row using gridview

I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page reloads except the row I am
trying to delete is still there. I believe it is something really easy, but I
cannot see it. The stored procedue works when run in QA. Can someone tell me
what I am doing wrong/missing that is keeping the delete command from working
in the gridview? Thank you.

I am trying to delete a row out of a line item table (ProjectLocationLI)
joining projects (projectid) and locations (locationid)

--ProjectLocationLI Table
CREATE TABLE [dbo].[ProjectLocationLI] (
[ProjectLocationLIID] [int] IDENTITY (1, 1) NOT NULL ,
[ProjectID] [int] NOT NULL ,
[LocationID] [int] NOT NULL
) ON [PRIMARY]
GO


--Gridview and datasource code

<asp:GridView ID="gvLocations" runat="server"
AutoGenerateColumns="False" CellPadding="4"
BorderColor="#5D7B9D" ForeColor="#333333" GridLines="None"
style="padding:1px; margin-top: 25px; margin-left: 10px;" Width="215px"
BorderStyle="Solid"
BorderWidth="1px"
DataKeyNames="LocationID" DataSourceID="SqlDataSource1">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/icons/canceledit_icon.gif"
DeleteImageUrl="~/images/icons/delete_icon.gif"
EditImageUrl="~/images/icons/edit_icon.gif" ShowEditButton="True"
UpdateImageUrl="~/images/icons/update_icon.gif" />
<asp:CommandField ButtonType="Image"
DeleteImageUrl="~/images/icons/delete_icon.gif"
DeleteText="" ShowDeleteButton="True" />
<asp:BoundField DataField="Name" HeaderText="Test Locations"
SortExpression="Name" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="LightGray" ForeColor="#284775" />
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CommonConnectionString %>"
SelectCommand="ListLocationsByProject"
SelectCommandType="StoredProcedure" DeleteCommand="DeleteLocationFromProject"
DeleteCommandType="StoredProcedure" UpdateCommand="UpdateLocation"
UpdateCommandType="StoredProcedure" InsertCommand="InsertLocation"
InsertCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="projectID" SessionField="ProjectID"
Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="projectID" Type="int32" />
<asp:Parameter Name="locationID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="locationID" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

--Stored Procedure being used
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE DeleteLocationFromProject (@projectID int, @locationID int)
AS

DELETE FROM ProjectLocationLI
WHERE ProjectID = @projectID AND LocationID = @locationID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Nov 21 '06 #1
0 1586

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by NateDawg | last post: by
reply views Thread by Terence | last post: by
3 posts views Thread by tarscher | last post: by
4 posts views Thread by Wannabe | last post: by
11 posts views Thread by Ed Dror | last post: by
2 posts views Thread by Michael | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.