This is a migrated thread and some comments may be shown as answers.

Delete and Update

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Barlet Hamzai
Top achievements
Rank 1
Barlet Hamzai asked on 18 Mar 2010, 01:19 PM
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.ObjectByVal 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 ObjectByVal 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 ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
 
    End Sub 
 
    Protected Sub RadGrid1_ItemDeleted(ByVal source As ObjectByVal 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 ObjectByVal 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 ObjectByVal 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 ObjectByVal e As EventArgs) Handles RadGrid1.DataBound 
        If Not String.IsNullOrEmpty(gridMessage) Then 
            DisplayMessage(gridMessage) 
        End If 
    End Sub 
End Class 
Allow Automatic Delete is set to 'TRUE'
Allow Automatic Insert is set to 'TRUE'
Allow Automatic Update is set to 'TRUE'

any suggestions

Thanks
Barlet Hamzai

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 19 Mar 2010, 08:04 AM
Hi Barlet,

You should be using Advanced databinding as opposed to Simple databinding.

Greetings,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Barlet Hamzai
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or