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

[Solved] RadGrid InsertCommand

2 Answers 291 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laslo Pertic
Top achievements
Rank 1
Laslo Pertic asked on 16 Jan 2010, 07:46 PM
Hi,

For some reason I can't get a reference to a control in the InsertCommand handler

This works for update:
Private Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.UpdateCommand
        Dim editItem As GridDataItem = DirectCast(e.Item, GridDataItem)
End Sub

But this does not:
Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand
            Dim insertItem As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem)
End Sub

I allways got this message:
Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridDataInsertItem'.

Help?
Thanks Laslo




2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2010, 08:04 AM
Hello Laslo,

This error can occur when you click on a button which resides in the command item template so as to trigger the InsertCommand, for which the e.Item instance is of type GridCommandItem, not GridDataInsertItem. If thats the case, then you can modify your code as follows to avoid the exception generated inside the InsertCommand handler:
vb:
Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand             
    Dim insertedItem As GridDataInsertItem = DirectCast(e.Item.OwnerTableView.GetInsertItem(), GridDataInsertItem) 
End Sub 

Thanks
Princy.
0
Laslo Pertic
Top achievements
Rank 1
answered on 18 Jan 2010, 06:13 PM
Thanks Princy. It's working great!
Tags
Grid
Asked by
Laslo Pertic
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Laslo Pertic
Top achievements
Rank 1
Share this question
or