I used from the training book the delete command. The problem that I am having is when I try to delete a record in the RadGrid, I get the following error:
Object referance not set to an instance of an object
The weird thing is I got it from the Telerik RadControls Ajax book and besides that I have no clue. See attached code:
| Imports System.Data.SqlClient |
| Imports Telerik.Web.UI |
| Partial Class EmployeeFamily |
| Inherits System.Web.UI.Page |
| Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand |
| Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
| Dim MemberFamilyID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("MemberFamilyID").ToString() |
| Try |
| 'Delete command execute |
| SqlDataSource1.DeleteCommand = "DELETE FROM MemberFamilyInfo Where MemberFamilyID = '" + MemberFamilyID + "'" |
| Catch ex As Exception |
| RadGrid1.Controls.Add(New LiteralControl("Unable to delete MemberFamily. Reason: " + ex.Message)) |
| e.Canceled = True |
| End Try |
| End Sub |
| End Class |