Radgrid ItemDataBound

This article provides a code example of how to use the Telerik RadGrid ItemDataBound event

Related Articles

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

Change the background color of an entire row

Set the Text of a GridBoundColumn

Set the image in a GridBoundColumn

 

General Example

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        Dim oRow As DataRowView
 
        If TypeOf e.Item Is Telerik.Web.UI.GridDataItem Then
            'cast e.item
            Dim item As GridDataItem = e.Item
 
            'this gives us access to the data side of things
            oRow = CType(e.Item.DataItem, DataRowView)
            Dim strStatus As String = oRow("status")
            Dim intID As Int32 = oRow("ID")
 
            'get a reference to a TEMPLATED control
            Dim hypSubject As HyperLink = CType(e.Item.FindControl("hypSubject"), HyperLink)
            hypSubject.Text = oRow("subject")
 
            'use business logic on the control
            If strStatus = "Article" Then
                hypSubject.NavigateUrl = "~/Article.aspx?ArticleID=" & intID
            Else
                hypSubject.NavigateUrl = "~/Thread.aspx?threadid=" & intID
            End If
 
            'get an indirect reference to a GridBoundColumn
            Dim oItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            oItem("itemdesc").ForeColor = System.Drawing.Color.Red
            oItem("itemdesc").Font.Bold = True
 
            'get a direct reference to a GridButtonColumn
            Dim btnSopnumber As LinkButton = CType(item("sopnumbe").Controls(0), LinkButton)
            btnSopnumber.Enabled = False
 
        End If
 
        'used to reference the group headers
        If TypeOf e.Item Is GridGroupHeaderItem Then
            oRow = CType(e.Item.DataItem, DataRowView)
            Dim bLocked As Boolean = oRow("Locked")
            If bLocked Then
                Dim btnReceive As RadButton = CType(e.Item.FindControl("btnReceive"), RadButton)
                btnReceive.Visible = False
            End If
 
        End If
 
    End Sub

 

 

 


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