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

Unable to delete using gridview

P: n/a
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 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I think Your ButtonField for the delete button is incomplete. Add the
following:

CommandName="Delete"

such that it looks like this:

<asp:CommandField ButtonType="Image"
CommandName="Delete"
DeleteImageUrl="~/images/icons/delete_icon.gif"
DeleteText="" ShowDeleteButton="True" />
On Mon, 20 Nov 2006 09:07:02 -0800, Wannabe
<Wa*****@discussions.microsoft.comwrote:
>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
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 20 '06 #2

P: n/a
Thanks for the reply, but that did not work. I get an error "CommandName is
not a valid attribute for commandfield"

If it helps, it seems if I modify my stored procedure to only require one
parameter of the project id, it will delete the item. But that is for
deleting an entry in the location table itself and I just want to delete the
entry out of the line item table.

"Rad [Visual C# MVP]" wrote:
I think Your ButtonField for the delete button is incomplete. Add the
following:

CommandName="Delete"

such that it looks like this:

<asp:CommandField ButtonType="Image"
CommandName="Delete"
DeleteImageUrl="~/images/icons/delete_icon.gif"
DeleteText="" ShowDeleteButton="True" />
On Mon, 20 Nov 2006 09:07:02 -0800, Wannabe
<Wa*****@discussions.microsoft.comwrote:
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
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 20 '06 #3

P: n/a
At the place where the delete takes place in code - make sure both items in
the WHERE clause are getting populated, and then passed to the stored
procedure. Naturally, if they're not populated, they won't get there and
nothing will get deleted, which is what is happening, in your case.

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"Wannabe" <Wa*****@discussions.microsoft.comwrote in message
news:22**********************************@microsof t.com...
Thanks for the reply, but that did not work. I get an error "CommandName
is
not a valid attribute for commandfield"

If it helps, it seems if I modify my stored procedure to only require one
parameter of the project id, it will delete the item. But that is for
deleting an entry in the location table itself and I just want to delete
the
entry out of the line item table.

"Rad [Visual C# MVP]" wrote:
I think Your ButtonField for the delete button is incomplete. Add the
following:

CommandName="Delete"

such that it looks like this:

<asp:CommandField ButtonType="Image"
CommandName="Delete"
DeleteImageUrl="~/images/icons/delete_icon.gif"
DeleteText="" ShowDeleteButton="True" />
On Mon, 20 Nov 2006 09:07:02 -0800, Wannabe
<Wa*****@discussions.microsoft.comwrote:
>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
--

Bits.Bytes.
http://bytes.thinkersroom.com

Nov 20 '06 #4

P: n/a
At the risk of sounding totally dumb, how can I check to make sure the
parameters are being populated? I am using the gridview control and I used
the smart tag and configured which stored prodedure to use through that and
did not write any code.

"David Wier" wrote:
At the place where the delete takes place in code - make sure both items in
the WHERE clause are getting populated, and then passed to the stored
procedure. Naturally, if they're not populated, they won't get there and
nothing will get deleted, which is what is happening, in your case.

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"Wannabe" <Wa*****@discussions.microsoft.comwrote in message
news:22**********************************@microsof t.com...
Thanks for the reply, but that did not work. I get an error "CommandName
is
not a valid attribute for commandfield"

If it helps, it seems if I modify my stored procedure to only require one
parameter of the project id, it will delete the item. But that is for
deleting an entry in the location table itself and I just want to delete
the
entry out of the line item table.

"Rad [Visual C# MVP]" wrote:
I think Your ButtonField for the delete button is incomplete. Add the
following:
>
CommandName="Delete"
>
such that it looks like this:
>
<asp:CommandField ButtonType="Image"
CommandName="Delete"
DeleteImageUrl="~/images/icons/delete_icon.gif"
DeleteText="" ShowDeleteButton="True" />
>
>
On Mon, 20 Nov 2006 09:07:02 -0800, Wannabe
<Wa*****@discussions.microsoft.comwrote:
>
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
--
>
Bits.Bytes.
http://bytes.thinkersroom.com
>


Nov 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.