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!