I am using GridImageColumn for displaying an icon if the value in a table column (HasRead) which is bound to the RadGrid Control is false.
Here is the aspx code..
<
Telerik:RadGrid
ID
=
"TelerikThread"
Width
=
"97%"
AllowSorting
=
"True"
PageSize
=
"15"
OnItemDataBound
=
"TelerikThread_ItemDataBound"
AllowPaging
=
"True"
AllowMultiRowSelection
=
"True"
runat
=
"server"
Gridlines
=
"None"
>
<
MasterTableView
Width
=
"100%"
Summary
=
"RadGrid table"
AutoGenerateColumns
=
"false"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
Columns
>
<
Telerik:GridImageColumn
UniqueName
=
"GridImageColumn"
SortExpression
=
"HasRead"
HeaderText
=
"Unread"
DataImageUrlFields
=
"HasRead"
>
</
Telerik:GridImageColumn
>
Below is the code behind
protected void TelerikThread_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TableCell flag = (TableCell)item["HasRead"];
if (flag.Text == "false")
{
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)item["GridImageColumn"].Controls[0];
img.ImageUrl = "./web/Themes/default/images/post_status_new_ln.gif";//set image url
}
else
{
TableCell cell = (TableCell)item["GridImageColumn"];
cell.Text = " ";//clears image column
}
}
}
I'm getting exception in the line
GridDataItem item = (GridDataItem)e.Item;
"Cannot cast e.item to GridDataItem"Please help me resolving this..
Thanks in advance.