TelerikDeveloper.com

TelerikDeveloper.com

sgray128 3/9/2012 5:23:20 PM

Telerik - RadGrid ItemCommand examples

There are a few gotchas using the Telerik RadGrid ItemCommand event. I ran into one today... this code sample will help speed development by providing the code that you need to code the ItemCommand event


Private Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
 
    'be sure that you're responding to the right kind of row
    '=======================
    'DATA row
    '=======================
    If TypeOf e.Item Is GridDataItem Then
        If e.CommandName = "Select" Then
            'requires that the referenced field be in the DataKeyValues in the grid
            Session("itemnmbr") = RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("itemnmbr")
        End If
    End If
 
    '=======================
    'GROUP row
    '=======================
    If TypeOf e.Item Is GridGroupHeaderItem Then
        If e.CommandName = "Select" Then
            'requires that the referenced field be in the DataKeyValues in the grid
            Dim intFirstChildRowIndex As Int32 = CType(e.Item, GridGroupHeaderItem).GetChildItems.First.ItemIndex
            Session("itemnmbr") = RadGrid1.MasterTableView.DataKeyValues(intFirstChildRowIndex)("itemnmbr")
        End If
 
    End If
 
End Sub