ItemDataBound Event
Fired after an item is databound to the RadGrid control.
Examples
Customizing auto-generated columns
If you need to customize the cells of a given column and you do not know the UniqueNames of the columns, you could loop through the AutoGeneratedColumns collection of the current GridTableView and pick the UniqueName of each column fulfilling a given condition and use it to access a cell in the current row. That can be achieved in the ItemDataBound event.
Event Parameters
-
(object)
sender- The control that fires the event
-
(GridItemEventArgs)
e-
Event arguments
-
(boolean)
e.CanceledSet to true to cancel the default event execution, if available. The ItemDataBound event cannot be cancelled.
-
(GridItemEventInfo)
e.EventInfoEvent info object. Cast to derrived classes to obtain appropriate instance.
-
(GridItem)
e.ItemGets the GridItem which fired the event.
-
-
Attaching the event
In the Markup
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
</telerik:RadGrid>
In the Code behind
protected void Page_Init(object sender, EventArgs e)
{
RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
}
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
AddHandler RadGrid1.ItemDataBound, AddressOf RadGrid1_ItemDataBound
End Sub
The event handler
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
bool canceled = e.Canceled;
GridItemEventInfo eventInfo = e.EventInfo;
GridItem item = e.Item;
}
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
Dim canceled As Boolean = e.Canceled
Dim eventInfo As GridItemEventInfo = e.EventInfo
Dim item As GridItem = e.Item
End Sub
Examples
Customizing auto-generated columns
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
{
if (col.DataType == typeof(int))
{
item[col.UniqueName].Font.Bold = true;
}
}
}
}
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
For Each col As GridColumn In RadGrid1.MasterTableView.AutoGeneratedColumns
If col.DataType Is GetType(Integer) Then
item(col.UniqueName).Font.Bold = True
End If
Next
End If
End Sub