Hello there,
I am trying to use RadGrids own Insert/Update/Delete method in order to edit or delete any records i want.
I have 2 columns on my table Group_id and Group_Name where group_id is Auto Increment.
I copy and pasted the code from http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/alleditablecolumns/defaultcs.aspx for VB.NET and modified but it does nothing.
When I edit and press update button it says: Group with ID 15 is updated! but nothing changes! also when I press Delete button nothing happens...
This is my code
Imports System.Data.SqlClient |
Imports Telerik.Web.UI |
Imports System.Drawing |
Partial Class category |
Inherits System.Web.UI.Page |
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load |
'Put user code to initialize the page here |
RadGrid1.DataBind() |
End Sub |
Protected Sub btninsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btninsert.Click |
Dim sConnStr As String = "Data Source=Barlet-HP\SQLEXPRESS;Initial Catalog=KDN;Integrated Security=True" |
Dim cnBKTest As New SqlConnection(sConnStr) |
Dim cmdTest As New SqlCommand("addGroup", cnBKTest) |
cmdTest.CommandType = Data.CommandType.StoredProcedure |
cmdTest.Parameters.Add(New SqlParameter("@Group_Name", Data.SqlDbType.VarChar)) |
cmdTest.Parameters("@Group_Name").Value = TextBox1.Text.ToString |
cnBKTest.Open() |
cmdTest.ExecuteNonQuery() |
cnBKTest.Close() |
RadGrid1.DataBind() |
Label2.Text = "Last Inserted Category is: " & TextBox1.Text |
TextBox1.Text = "" |
TextBox1.Focus() |
'''''''''''''''''''''''''''''''''''''''''''''' |
End Sub |
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
End Sub |
Protected Sub RadGrid1_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles RadGrid1.ItemDeleted |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim id As String = item.GetDataKeyValue("Group_id").ToString() |
If Not e.Exception Is Nothing Then |
e.ExceptionHandled = True |
SetMessage("Group with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message) |
Else |
SetMessage("Group with ID " + id + " is deleted!") |
End If |
End Sub |
Protected Sub RadGrid1_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles RadGrid1.ItemUpdated |
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
Dim id As String = item.GetDataKeyValue("Group_id").ToString() |
If Not e.Exception Is Nothing Then |
e.KeepInEditMode = True |
e.ExceptionHandled = True |
SetMessage("Group with ID " + id + " cannot be updated. Reason: " + e.Exception.Message) |
Else |
SetMessage("Group with ID " + id + " is updated!") |
End If |
End Sub |
Protected Sub RadGrid1_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted |
If Not e.Exception Is Nothing Then |
e.ExceptionHandled = True |
e.KeepInInsertMode = True |
SetMessage("Product cannot be inserted. Reason: " + e.Exception.Message) |
Else |
SetMessage("New product is inserted!") |
End If |
End Sub |
Private Sub DisplayMessage(ByVal text As String) |
RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text))) |
End Sub |
Private Sub SetMessage(ByVal message As String) |
gridMessage = message |
End Sub |
Private gridMessage As String = Nothing |
Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.DataBound |
If Not String.IsNullOrEmpty(gridMessage) Then |
DisplayMessage(gridMessage) |
End If |
End Sub |
End Class |
Allow Automatic Insert is set to 'TRUE'
Allow Automatic Update is set to 'TRUE'
any suggestions
Thanks
Barlet Hamzai