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

3 posts, 0 answers
  1. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 03 Sep 2013 Link to this post


    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2013 Link to this post

    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
  3. Carlos
    Carlos avatar
    2 posts
    Member since:
    Jun 2017

    Posted 05 Jul 2017 in reply to Princy Link to this post

    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


          

Back to Top