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

Image replacement for GridHyperLinkColumn

12 Answers 375 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marta
Top achievements
Rank 1
Marta asked on 14 May 2009, 11:18 AM
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

12 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 May 2009, 12:38 PM
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.
0
Marta
Top achievements
Rank 1
answered on 14 May 2009, 02:32 PM

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:)

0
Marta
Top achievements
Rank 1
answered on 16 Jun 2009, 04:40 PM
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!
0
Derek
Top achievements
Rank 1
answered on 13 Aug 2009, 07:10 PM
Can anyone provide a VB version of this code?
0
Shinu
Top achievements
Rank 2
answered on 14 Aug 2009, 04:18 AM
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
0
Steve
Top achievements
Rank 1
answered on 08 Jun 2011, 02:57 PM

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.


0
Veli
Telerik team
answered on 13 Jun 2011, 09:29 AM
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.

0
Tarang
Top achievements
Rank 1
answered on 27 Jun 2011, 09:08 PM
Hi,  Do we have this property available? if so then in which version i can find it?
0
Veli
Telerik team
answered on 29 Jun 2011, 11:23 AM
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.

0
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 26 Jul 2017, 04:07 AM
How does this work when both the image path and hyperlink are dynamic, coming from the datatable that is bound to the grid? GridHyperLinkColumn has an ImageUrl property but no DataImageUrlFields property.
0
Marin Bratanov
Telerik team
answered on 28 Jul 2017, 12:55 PM

Hello Neil,

For such cases you can use a TemplateColumn and add controls inside according to your concrete requirements. For example, you can add an asp:HyperLink and data bind its CssClass or directly information in its style attribute. Or, you can add an asp:Image inside and bind its ImageUrl.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 29 Jul 2017, 02:47 AM
Simple. Thanks.
Tags
Grid
Asked by
Marta
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marta
Top achievements
Rank 1
Derek
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Veli
Telerik team
Tarang
Top achievements
Rank 1
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
Marin Bratanov
Telerik team
Share this question
or