RadGrid for ASP.NET

RadGrid Send comments on this topic.
ItemDataBound Event
See Also  Example
Telerik.WebControls Namespace > RadGrid Class : ItemDataBound Event


Occurs when a data iten is bound to data in a Telerik RadGrid control.

 

Example

The following code example demonstrates how to use the ItemDataBound event to modify the value of a field in the data source before it is displayed in a Telerik RadGrid control.  

Event Data

The event handler receives an argument of type GridItemEventArgs containing data related to this event. The following GridItemEventArgs properties provide information specific to this event.

PropertyDescription
Canceled Set to true to cancel the default event execution, if available. The ItemCreated and ItemDataBound events cannot be cancelled.
EventInfo Event info object. Cast to derrived classes to obtain the appropriate instance
Item  
 

 

Namespace: Telerik.WebControls
Assembly: RadGrid (in RadGrid.dll)

Syntax

Visual Basic (Declaration) 
Public Event ItemDataBound() As GridItemEventHandler
Visual Basic (Usage)Copy Code
Dim instance As RadGrid
Dim handler As GridItemEventHandler
 
AddHandler instance.ItemDataBound, handler
C# 
public event GridItemEventHandler ItemDataBound()
 

Event Data

The event handler receives an argument of type GridItemEventArgs containing data related to this event. The following GridItemEventArgs properties provide information specific to this event.

PropertyDescription
Canceled Set to true to cancel the default event execution, if available. The ItemCreated and ItemDataBound events cannot be cancelled.
EventInfo Event info object. Cast to derrived classes to obtain the appropriate instance
Item  

Example

The following code example demonstrates how to use the ItemDataBound event to modify the value of a field in the data source before it is displayed in a Telerik RadGrid control.
Visual BasicCopy Code
<%@ Page Language="VB" <see cref="!:> <"/>@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs)
        If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then
            Dim item As Telerik.WebControls.GridDataItem
            item = e.Item
            item("CustomerID").Text = "Telerik"
        End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <rad:RadGrid
            DataSourceID="SqlDataSource1"
            ID="RadGrid1"
            runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
        </rad:RadGrid>
        <!-- This example uses Microsoft SQL Server And connects -->
        <!-- To the Northwind sample database. Use an ASP.NET -->
        <!-- expression To retrieve the connection String value -->
        <!-- from the Web.config file. -->
        <asp:SqlDataSource
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<<see cref="!:NorthwindConnectionString">$ ConnectionStrings</see>>"
            SelectCommand="SELECT TOP 5 [CustomerID], [ContactName], [CompanyName] FROM [Customers]">
        </asp:SqlDataSource>
    
</body>
</html>

Remarks

Before the Telerik RadGrid control can be rendered, each item in the control must be bound to a record in the data source. The ItemDataBound event is raised when a data item (represented by a GridItem object) is bound to data in the Telerik RadGrid control. This allows you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the item, whenever this event occurs.

A GridItemEventArgs object is passed to the event-handling method, which allows you to access the properties of the item being bound. You can determine which item type (header item, data pager item, and so on) is being bound by using the Item.ItemType property.

Note that the changes made to the item control and its children does persist into the ViewState. This event is fired as a result of a data-binding of Telerik RadGrid contorl. This event is fired for items of type:

  • GridDataItem
  • GridEditFormItem
  • GridHeaderItem
  • GridPagerItem
  • GridFooterItem

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also