In order to replace all broken image links in my RagGrid, I'm using the following code in my ItemDataBound() event to add the "onError" attribute to my GridImageColumn. The code works great until a Grouping is performed on the RadGrid, which throws an exception of "Specified argument was out of the range of valid values.". Is there any workaround for this? I tried checking if Controls.Count > 0 but then the attribute is never added.
void
uxDirectoryGrid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
//set the onError attribute to handle images which do not exist
var imageColumnIndex = e.Item.OwnerTableView.Columns.FindByUniqueName(
"AccountName"
).OrderIndex;
var imageCell = e.Item.Cells[imageColumnIndex];
var image = imageCell.Controls[0]
as
Image; //<--- BOMBS OUT HERE: Specified argument was out of the range of valid values
if
(image !=
null
)
{
image.Attributes[
"onError"
] =
"this.src='EmployeePhotos/404.jpg'"
;
}
}
}