I try to use the Rad Grid Delete Command to delete a row in the RadGrid using server side store proc. The index property reads correctly but the actual value of the field is null.
TABLE
-------------------------------------------------------------------------------------------------------------------------------------------------
USE [xxxx]
GO
/****** Object: Table [dbo].[TemplateAreasPractice] Script Date: 03/08/2010 21:52:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TemplateAreasPractice](
[TemplateAreasPracticeId] [int] IDENTITY(1,1) NOT NULL,
[CategoryId] [int] NULL,
[ProfileId] [int] NULL,
[TemplateAreasPracticePorcent] [int] NULL,
[TemplateAreasPracticeDate] [datetime] NULL,
CONSTRAINT [PK_TemplateAreasPractice] PRIMARY KEY CLUSTERED
(
[TemplateAreasPracticeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TemplateAreasPractice] ADD CONSTRAINT [DF_TemplateAreasPractice_TemplateAreasPracticeDate] DEFAULT (getdate()) FOR [TemplateAreasPracticeDate]
GO
Store Proc
------------------------------------------------------------------------------------------------------------------------------------------------------------
USE [xxx]
GO
/****** Object: StoredProcedure [dbo].[Delete_TemplateAreasPractice] Script Date: 03/08/2010 21:52:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Christian Rodriguez
-- Create date: 3-8-2010
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[Delete_TemplateAreasPractice]
-- Add the parameters for the stored procedure here
@TemplateAreasPracticeId int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DELETE FROM TemplateAreasPractice
WHERE (TemplateAreasPracticeId = @TemplateAreasPracticeId)
END
GO
HTML
------------------------------------------------------------------------------------------------------------------------------------------
<telerik:RadGrid ID="RadGridAreaofPractice" runat="server" AllowPaging="True"
GridLines="None" AutoGenerateColumns="False" OnDeleteCommand="RadGridAreaofPractice_DeleteCommand">
<MasterTableView>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName= "DeleteColumn" />
<telerik:GridBoundColumn DataField="TemplateAreasPracticeId" HeaderText="TemplateAreasPracticeId" SortExpression="TemplateAreasPracticeId" UniqueName="TemplateAreasPracticeId" />
<telerik:GridBoundColumn DataField="CategoryDesc" HeaderText="Category" SortExpression="Category" UniqueName="Category" />
<telerik:GridBoundColumn DataField="TemplateAreasPracticePorcent" HeaderText="Porcent" SortExpression="Porcent" UniqueName="Porcent" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
ASPX.VB
--------------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub RadGridAreaofPractice_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridAreaofPractice.DeleteCommand
Dim id As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("TemplateAreasPracticeId").ToString()
If id > "" Then
Dim ConnectionString As New XXX
Dim sConnection As String = ConnectionString.XXX
Dim connection As SqlConnection = New SqlConnection(sConnection)
'Delete
Dim objCommand_Delete_TemplateAreasPractice As SqlCommand = New SqlCommand("Delete_TemplateAreasPractice", connection)
objCommand_Delete_TemplateAreasPractice.Connection.Open()
objCommand_Delete_TemplateAreasPractice.CommandType = Data.CommandType.StoredProcedure
objCommand_Delete_TemplateAreasPractice.Parameters.AddWithValue("@TemplateAreasPracticeId", id)
objCommand_Delete_TemplateAreasPractice.ExecuteNonQuery()
objCommand_Delete_TemplateAreasPractice.Connection.Close()
objCommand_Delete_TemplateAreasPractice.Dispose()
'close database connection
connection.Close()
connection.Dispose()
End If
End Sub 'RadGridAreaofPractice_DeleteCommand