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

Related Articles

... and you 'll find more on the Telerik ASPNET Grid Menu

 

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
            'cast e.item
            Dim item As GridDataItem = e.Item
 
            'requires that the referenced field be in the DataKeyValues in the grid
            Session("itemnmbr") = RadGrid1.MasterTableView.DataKeyValues(e.Item.ItemIndex)("itemnmbr")
 
            'get a reference to a GridButtonColumn
            Dim btnSopnumber As LinkButton = CType(item("sopnumbe").Controls(0), LinkButton)
            btnSopnumber.Enabled = False
        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

 

If TypeOf e.Item Is GridDetailTemplateItem Then
    'requires that the referenced field be in the DataKeyValues in the grid
    Dim intFirstChildRowIndex As Int32 = CType(e.Item, GridDetailTemplateItem).RowIndex
 
    Dim strSopnumber As String = RadGrid1.MasterTableView.DataKeyValues(intFirstChildRowIndex)("sopnumbe")
    Dim intSoptype As Int16 = RadGrid1.MasterTableView.DataKeyValues(intFirstChildRowIndex)("soptype")
End If

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences