This is a migrated thread and some comments may be shown as answers.

GridImageColumn databinding code

3 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karthi
Top achievements
Rank 1
Karthi asked on 04 Mar 2011, 08:40 AM
Hi,

    I'm using GridImageColumn in to display a icon if the value in the table is false.

Please find the aspx code below.

<

 

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>

 


Please find the aspx.cs code below

 

protected void TelerikThread_ItemDataBound(object sender, GridItemEventArgs e)

 

 

{

 

 

if (e.Item is GridDataItem)

 

 

{

 

 

GridDataItem item = (GridDataItem)e.Item.DataItem;

 

 

 

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/imges/post_status_new_ln.gif";//set image url

 

}

 

else

 

{

 

TableCell cell = (TableCell)item["GridImageColumn"];

 

 

cell.Text =

" ";//clears image column

 

}

}

}


Exception is thrown in this line

 

 

GridDataItem

 

item = (GridDataItem)e.Item.DataItem;

 

 

 


Help me with the solution

 

 

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Mar 2011, 08:58 AM
Hello Karthi,

You can access grid data item usingGridDataItem item = (GridDataItem)e.Item' .

-Shinu.
0
Karthi
Top achievements
Rank 1
answered on 04 Mar 2011, 09:06 AM

Hi
If I access it as you mentioned I'm getting exception as "Cannot find cell bound to 'HasRead'" in the line

TableCell flag = (TableCell)item["HasRead"];

Thanks,
Karthi
0
Tsvetina
Telerik team
answered on 09 Mar 2011, 02:20 PM
Hello Karthi,

This is so because you should use the column UniqueName when referencing the table cell:

TableCell flag = (TableCell)item["GridImageColumn"];

All the best,
Tsvetina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Karthi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Karthi
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or