Image replacement for GridHyperLinkColumn

10 posts, 1 answers
  1. Marta
    Marta avatar
    31 posts
    Member since:
    Apr 2009

    Posted 14 May 2009 Link to this post

    Hi, I'm having some problems with my grid. I have a GridHyperLinkColumn which has a link whose url is composed using an id retrieved through a select statement to a database. I would like the link in the grid to be an image and not text, I tried using the GridButtonColumn and the GridTemplateColumn to achieve this but neither works, since what I need is to be able to pass the DataNavigateUrlFormatString value and the DataNavigateUrlFields like in the GridHyperLinkColumn to be able to pass the id of the content to go to the correct page. As I have said, the link should be an image and not text. I tried using a css class to style this like I normally would but couldn't get it to work.

    Can anyone help please?

    Thanks a lot,
    Marta
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 May 2009 Link to this post

    Hello Marta,

    You can access the hyperlink for the hyperlink column and set its ImageUrl property to the required image url as shown below:
    c#:
      protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                HyperLink hyplnk = (HyperLink)item["HyperLinkColumnUniqueName"].Controls[0]; 
                hyplnk.ImageUrl = "~/image.gif";          
            } 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marta
    Marta avatar
    31 posts
    Member since:
    Apr 2009

    Posted 14 May 2009 Link to this post

    Hi,

    Thanks for your reply. I tried what you suggested, but I can't get the image to appear, I don't know why...

    My GridHyperLinkColumn is as follows:

    <telerik:GridHyperLinkColumn
     DataNavigateUrlFormatString="/lms_bd/FichaConteudo.aspx?conteudo={0}" Target="_self"  DataTextFormatString="my edit page" DataNavigateUrlFields="IDConteudo" UniqueName="VerFicha" HeaderText="Ver Ficha" Text="Ver" />

    The name of the radgrid is Conteudos.

    The code in my .cs file is:

        protected void Conteudos_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HyperLink hyplnk = (HyperLink)item["VerFicha"].Controls[0];
                hyplnk.ImageUrl = "~/imagens/bt_arvore_ficheiro.gif";
            }
        }

    Any suggestions to solve this problem?
    Thanks:)

  5. Marta
    Marta avatar
    31 posts
    Member since:
    Apr 2009

    Posted 16 Jun 2009 Link to this post

    I got it to work!

     

    if (e.Item is GridDataItem)

     

    {

     

    GridDataItem item = (GridDataItem)e.Item;

     

     

    HyperLink hyplnk = (HyperLink)item["Editar"].Controls[0];

     

    hyplnk.ImageUrl =

    "~/imagens/bt_editar.gif";

     

    }


    Before it wasn't working because of an error on my page.
    thanks!
  6. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 13 Aug 2009 Link to this post

    Can anyone provide a VB version of this code?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2009 Link to this post

    Hi Derek,

    Here is the code in VB:

     
     
     
        Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) 
            If TypeOf e.Item Is GridDataItem Then 
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
                Dim hyplnk As HyperLink = DirectCast(item("HyperLinkColumnUniqueName").Controls(0), HyperLink) 
                hyplnk.ImageUrl = "~/image.gif" 
            End If 
        End Sub 
     
     

    Thanks
    Shinu
  8. Steve
    Steve avatar
    11 posts
    Member since:
    Feb 2011

    Posted 08 Jun 2011 Link to this post


    I think its a little ridiculous to have to set the hyperlinks ImageURL on the RowDataBound event. Can a request be made to the Dev team to add a property to the GridHyperLinkColumn class in the RadGrid control to include a property for something like "HyperLinkImageURL" and if the field has a value, override the Text field so the Image is displayed instead of the text (or just display both)... ??

    I guess its not that big of a deal to set the image on RowDataBound, but having a "HyperLinkImageURL" makes reading the source easier if a property existed.


  9. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 13 Jun 2011 Link to this post

    Your feedback has been reported to the dev team and they will consider adding a GridHyperlinkColumn property for that.

    Greetings,
    Veli
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  10. Tarang
    Tarang avatar
    5 posts
    Member since:
    Sep 2012

    Posted 27 Jun 2011 Link to this post

    Hi,  Do we have this property available? if so then in which version i can find it?
  11. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 29 Jun 2011 Link to this post

    This feature is added for the upcoming Q2 2011 beta release expected by the end of the week.

    Greetings,
    Veli
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017