I'm new to asp.net and have been learning as I go, however I have got to a point where I can't find any help on line about my current problem.
I have created a Gridview using the following code
And the associated SqlDatasource
This works fine when I click on the Edit/Update for any given row in the gridview; i.e. I can change the data in either StockCode, TypeNo, Iss, any two or all three, click update and the page goes away and updates the database, as I'd expect. But it doesn't work when I click on the Delete link. It doesn't throw an error it cycles through the Page_Load sub routine (like the edit/update does) but doesn't actually delete the row in the database - so it remains in gridview too.
I'm sure I have the stored procedure permission correct as they are the same as the update stored procedure - in fact I've remove my permissions from the stored procedure and got a permissions error. So I think I must have a problem in the asp.net side, what am I missing?
Of Note: the CssClass="invis" sets the <td> and <th> display:none; so those two cells don't appear to the users.
Here's a copy of the Stored Procedure in case I've messed that up - but it works when I fire it direct from MS SQL Server Management Studio with a manually set parameter.
I have created a Gridview using the following code
Code:
<asp:GridView ID="GridViewTypeNo" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"">
<Columns>
<asp:BoundField DataField="StockCode" HeaderText="StockCode" SortExpression="StockCode"></asp:BoundField>
<asp:BoundField DataField="TypeNo" HeaderText="Type No" SortExpression="TypeNo"></asp:BoundField>
<asp:BoundField DataField="Iss" HeaderText="Issue" SortExpression="Iss"></asp:BoundField>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True">
</asp:CommandField>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("ChangeNoteUID")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtChangeNoteUID" runat="server" Text='<%# Bind("ChangeNoteUID") %>'></asp:Label>
</EditItemTemplate>
<HeaderStyle CssClass="invis"></HeaderStyle>
<ItemStyle CssClass="invis" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("ChangeNoteProdUID")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtChangeNoteProdUID" runat="server" Text='<%# Bind("ChangeNoteProdUID") %>'></asp:Label>
</EditItemTemplate>
<HeaderStyle CssClass="invis"></HeaderStyle>
<ItemStyle CssClass="invis" />
</asp:TemplateField>
</Columns>
</asp:GridView>
And the associated SqlDatasource
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:ChangeNoteConnectionString%>"
SelectCommand="SELECT [ChangeNoteUID], [ChangeNoteProdUID], [StockCode], [TypeNo], [Iss] FROM [dbo].[ChangeNoteProduct] WHERE [ChangeNoteUID] = @ChangeNoteUID"
UpdateCommand="[dbo].[sp_UpdateChangeNoteProduct]" UpdateCommandType="StoredProcedure"
DeleteCommand="[dbo].[sp_ChangeNoteDeleteProduct]" DeleteCommandType="StoredProcedure"
ProviderName="<%$ ConnectionStrings:ChangeNoteConnectionString.ProviderName %>">
<SelectParameters>
<asp:Parameter Name="ChangeNoteUID" Type="String" DefaultValue="" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ChangeNoteProdUID" Type="String" />
<asp:Parameter Name="ChangeNoteUID" Type="String" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ChangeNoteProdUID" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
This works fine when I click on the Edit/Update for any given row in the gridview; i.e. I can change the data in either StockCode, TypeNo, Iss, any two or all three, click update and the page goes away and updates the database, as I'd expect. But it doesn't work when I click on the Delete link. It doesn't throw an error it cycles through the Page_Load sub routine (like the edit/update does) but doesn't actually delete the row in the database - so it remains in gridview too.
I'm sure I have the stored procedure permission correct as they are the same as the update stored procedure - in fact I've remove my permissions from the stored procedure and got a permissions error. So I think I must have a problem in the asp.net side, what am I missing?
Of Note: the CssClass="invis" sets the <td> and <th> display:none; so those two cells don't appear to the users.
Here's a copy of the Stored Procedure in case I've messed that up - but it works when I fire it direct from MS SQL Server Management Studio with a manually set parameter.
Code:
USE [MPDB_Copy]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_ChangeNoteDeleteProduct] @ChangeNoteProdUID int
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM [ChangeNoteProduct] WHERE [ChangeNoteProdUID] = @ChangeNoteProdUID
END