Posted 2006-08.
From the SDK:
This event provides you with the last opportunity to access the data item before it is displayed on the client. After this event is raised, the data item is nulled out and no longer available.
In other words, this is your last chance to parse/format the data displayed to the client. For example, let's say you want to give an overall visual representation of how well (or not so well) the IT shop is meeting certain deadlines. Something like:
Days Overdue
| Assigned | Deadline | Completed | Task |
|
2006-01-07
|
2006-01-08
|
2006-01-09
|
Install M$ January Hotfixes
|
|
2006-02-07
|
2006-02-08
|
2006-02-08
|
Install M$ February Hotfixes
|
|
2006-03-07
|
2006-03-08
|
2006-03-07
|
Install M$ March Hotfixes
|
|
2006-04-07
|
2006-04-08
|
2006-04-12
|
Install M$ April Hotfixes
|
|
2006-05-07
|
2006-05-08
|
2006-05-10
|
Install M$ May Hotfixes
|
|
2006-06-07
|
2006-06-08
|
2006-06-07
|
Install M$ June Hotfixes
|
|
2006-07-07
|
2006-07-08
|
2006-07-18
|
Install M$ July Hotfixes
|
|
2006-08-07
|
2006-08-08
|
2006-08-14
|
Install M$ August Hotfixes
|
1. Set the ItemDataBound event handler:
<asp:datagrid id='tasker' runat='server'
onitemdatabound='highlight'
>
2. Provide the custom handler:
protected void highlight(object sender, DataGridItemEventArgs e) {
// we only want to highlight **data-bound** items!
if ( e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem
) {
DateTime deadline = DateTime.Parse(
DataBinder.Eval(e.Item.DataItem, "date_deadline").ToString()
);
DateTime completed = DateTime.Parse(
DataBinder.Eval(e.Item.DataItem, "date_completed").ToString()
);
// specifically, how many days overdue the task **completion**
// was from the task **deadline**
if ( (completed - deadline).Days >= Int32.Parse(due.SelectedValue))
// ^^^^^^^^^^^^^^^^^^^^^ subtraction operator and two DateTime objects
// returns a TimeSpan object
e.Item.BackColor = System.Drawing.Color.FromName("#ffff00");
}
}
The example binds a XML string to the DataGrid.