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

How to display text and image in the radgrid column / cell ?

2 Answers 1115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhanu
Top achievements
Rank 1
Bhanu asked on 03 Sep 2013, 03:23 PM

Hi,

We are using Telerik RadGrid version ASP.NET AJAX Q3 2009 SP2 with Visual Studio 2008 and IE 8. 
I have a read-only grid and one of the columns in the grid displays dates.
I would like to display a status icon / image (saved into .png file) next to the date text if the date is today's date.

For example : 09/03/2013 (image should be displayed here)

Can you help me to achieve this functionality ?

Thanks
Bhanu.


2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Sep 2013, 03:37 PM
HI Bhanu,

One way to set an image near date column is to use a GridTemplateColumn.Please try the below code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="OrderDate" UniqueName="OrderDate">
  <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderDate")%>'></asp:Label>
      <asp:Image ID="Image1" runat="server" ImageUrl="~/RadGrid6/image.jpg" Visible="false"/>
  </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            Label lbl = (Label)item.FindControl("Label1");//Access the label in template column
            string date = lbl.Text;
           //Your Condition to show the image
            {
                Image img = (Image)item.FindControl("Image1");//Access the image in template column
                img.Visible = true; //Set visibility
            }
        }
    }

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 05 Jul 2017, 06:44 PM

I got the next error:

 protected void grvHTE_ItemDataBound(object sender, GridItemEventArgs e)
     {
         if (e.Item is GridDataItem)
         {
             GridDataItem item = (GridDataItem)e.Item;
             Label lbl = (Label)item.FindControl("INFGACTIVOLabel");//Access the label in template column
            
             string active = lbl.Text;
             //Your Condition to show the image
             if (active == "1")
             {
                 Image imagen = (Image)item.FindControl("Image1");
                 
             }
         }
     }

 

Error4 Cannot convert type 'System.Web.UI.Control' to 'Image'C:\Users\JSSJZP0524\Documents\Visual Studio 2013\WebSites\TelerikMAPS\DCO\SWS.aspx.cs13433TelerikMAPS


      

Tags
Grid
Asked by
Bhanu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Carlos
Top achievements
Rank 1
Share this question
or