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

How can we add hyperlink column in RadGrid with Image

2 Answers 518 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KS
Top achievements
Rank 1
KS asked on 20 Jul 2010, 07:00 AM
I have requirement to add Image in the RadGrid as Hyperlink

Code-Behind is like this

 Protected Sub radgrid1_ItemDataBound(ByVal source As Object, ByVal e As GridItemEventArgs)

            If (e.Item.ItemType = GridItemType.Item) Then

                Dim HtmlImg As New System.Web.UI.WebControls.Image
                HtmlImg = CType(e.Item.FindControl("ImgMachine"), System.Web.UI.WebControls.Image)

                Dim ProductId As New HiddenField
                ProductId = CType(e.Item.FindControl("hdnOrderNumber"), HiddenField)

                HtmlImg.Attributes.Add("onclick", "javascript:window.open('http://www.myshoppingCart.no/OpenShopPackageTracker.aspx?installationID=21140000023&orderNumber=" & ProductId.Value.ToString() & "'); return false;")


            End If

        End Sub

Please help me with inline code for this

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jul 2010, 10:51 AM
Hello Kalit,

One solution is to use one GridTemplateColumn with Image in ItemTemplate instead of HyperLinkColumn. Then from code behind attach 'onclick' client event to the Image. Check out the following code snippet.

ASPX:
<telerik:GridTemplateColumn>
     <ItemTemplate>
         <asp:Image ID="Image1" runat="server" />
     </ItemTemplate>
 </telerik:GridTemplateColumn>

VB.Net:
Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim img As Image = DirectCast(item.FindControl("Image1"), Image)
        Dim ProductId As New HiddenField()
        ProductId = DirectCast(e.Item.FindControl("hdnOrderNumber"), HiddenField)
        img.Attributes.Add("onclick", "javascript:window.open('http://www.myshoppingCart.no/OpenShopPackageTracker.aspx?installationID=21140000023&orderNumber=" + ProductId.Value.ToString() & "'); return false;")
    End If
End Sub

 Another suggestion is directly attaching 'onclick' event to the Image by passing 'OrderNumber'(i think it is one of DataField in your DB) to the event handler.

ASPX:
<telerik:GridTemplateColumn>
   <ItemTemplate>
       <img alt="" src="../Images/Cancel.gif" onclick='openWindow(<%#Eval("OrderNumber") %>);' />
   </ItemTemplate>
</telerik:GridTemplateColumn>

Java Script:
<script type="text/javascript">
    function openWindow(value)
    {
      window.open(url);
    }
</script>

Thanks,
Princy.
0
Santodip
Top achievements
Rank 1
answered on 28 Sep 2010, 09:03 AM
Thanks ............... its really helpful
Tags
Grid
Asked by
KS
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Santodip
Top achievements
Rank 1
Share this question
or