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;
}
The event handler
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
bool canceled = e.Canceled;
GridItemEventInfo eventInfo = e.EventInfo;
GridItem item = e.Item;
}
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;
}
}
}
}