How to manipulate data in DB

4 posts, 0 answers
  1. FreshOne
    FreshOne avatar
    22 posts
    Member since:
    Jan 2010

    Posted 22 Feb 2010 Link to this post

    hi all,
    i just want to be sure that i'm working right with the grid..i manipulate data in the code behind, here is the ItemCommand sub

        Private Sub RadGrid2_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid2.ItemCommand  
            If e.CommandName = "Update" Then 
                If Page.IsValid Then 
                    Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
                    Dim objSection As New Sections(item.GetDataKeyValue("ID"))  
                    objSection.SectionName = CType(item.FindControl("txtSectionName"), TextBox).Text  
                    objSection.Update()  
                    e.Item.Edit = False 
                End If 
            ElseIf e.CommandName = "PerformInsert" Then 
                If Page.IsValid Then 
                    Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
                    Dim objSection As New Sections()  
                    objSection.SectionName = CType(item.FindControl("txtSectionName"), TextBox).Text  
                    objSection.LangID = Session("Language")  
                    objSection.SiteID = Session("Site")  
                    objSection.Insert()  
                    e.Canceled = True 
                    e.Item.OwnerTableView.IsItemInserted = False 
                    e.Item.OwnerTableView.Rebind()  
                End If 
            ElseIf e.CommandName = "Delete" Then 
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
                Dim objSection As New Sections(item.GetDataKeyValue("ID"))  
                objSection.Delete()  
            End If 
        End Sub 

    It's functioning well, but i want to be sure that my approach is correct, and there is no easier and better approach to do it.
    To be more specific:
    1. to get user inputs, i have to use FindControl function right? 

    2. to close the popup after success update i have to use
    e.Item.Edit = False 

    which don't work on insert so after success insert i use 
                    e.Canceled = True    
                    e.Item.OwnerTableView.IsItemInserted = False    
                    e.Item.OwnerTableView.Rebind()    

    3. on insert and update i need to use 
    Dim item As GridEditableItem = CType(e.Item, GridEditableItem)   

    but on delete i use
    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  


    Wht do u think? am i getting it right?
    thnx in advance
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 22 Feb 2010 Link to this post

    I would suggest using the InsertCommand, UpdateCommand and DeleteCommand events, instead of handling the ItemCommand event, to handle the respective operations.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. FreshOne
    FreshOne avatar
    22 posts
    Member since:
    Jan 2010

    Posted 22 Feb 2010 Link to this post

    hi robertw102 thnx for ur reply
    why? wht's the difference? does it affect the performance?
  5. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 22 Feb 2010 Link to this post

    It doesn't affect performance, although ItemCommand before the Insert/Update/Delete commands so two events get raised, it just makes more sense to handle the insert/update/delete operations using the correct event.
Back to Top