GridEditableItem

3 posts, 1 answers
  1. Santosh Pradhan
    Santosh Pradhan avatar
    10 posts
    Member since:
    Jul 2009

    Posted 12 Apr 2010 Link to this post

    I am using the FormTemplate to insert/update records from the grid. For most of the part the code is working fine. When I click the update button on the row in the grid, data is populated fine in the FormTemplate with the "Eval" command. The button for Insert/Update is also functioning well. 

    On the Insert/Update button I am setting properties like following -
    Text='<%# IIf (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'  CommandName='<%# IIf (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "PerformUpdate") %>'

     

    In the code behind I am calling stored procedures to insert or update:

    Protected Sub RadGridAssgn_ItemCommand( .........

         ..

        If e.CommandName = RadGrid.PerformInsertCommandName Then

            'Insert new item

            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim aH as String = CType(editableItem.FindControl("txtNotes"), TextBox).Text
            ...
            ...
            'Call Insert StoredProcedure and Insert Item
           ...
           'Rebind and Refresh Grid
        ElseIf e.CommandName = "PerformUpdate" Then
          'Update Item
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim aH as String = CType(editableItem.FindControl("txtNotes"), TextBox).Text
            ...
            ...
            'Call Update StoredProcedure and Insert Item
           ...
           'Rebind and Refresh Grid
        End If

    Insert part works fine. But I am having problem getting the update part working. The simple error I am getting at the following line:
            Dim aH as String = CType(editableItem.FindControl("txtNotes"), TextBox).Text

    The same code works fine in the INSERT mode. In Update mode FindControl does not find the "txtNotes" text box and returns Null - I get an error "Object reference not set to an instance of an Object."

    Any help is greatly appreciated!

    Thanks!

     

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Apr 2010 Link to this post

    Hello Santhosh,

    In order to find the TextBox in Update mode you should create an instance of GridEditFormItem instead of GridEditableItem. Hope the following code will help you.

    If e.CommandName = "PerformUpdate" Then 
            Dim edititem As GridEditFormItem = DirectCast(TryCast(e.Item, GridDataItem).EditFormItem, GridEditFormItem) 
            Dim aH As String = DirectCast(edititem.FindControl("txtNotes"), TextBox).Text 
    End If 

    Regards,
    Shinu.



  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Santosh Pradhan
    Santosh Pradhan avatar
    10 posts
    Member since:
    Jul 2009

    Posted 13 Apr 2010 Link to this post

    Thank you Shinu for the quick reply.

    It worked fine. Now there is only one small issue. After I perform Insert, the grid gets back to the normal view (not in edit mode, FormTemplate is removed) but after Update, the grid stays in the Edit mode (FormTemplate stays) and I need to click the "Cancel" button to remove the FormTemplate. How can I remove the FormTemplate after update is performed?

    Thanks,
    Santosh
Back to Top