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

create onclick event with image

2 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 29 Mar 2012, 08:22 PM
I was following an example I found on the site but for some, and it works up to teh point of finding the link buttons text.  I need the linkbuttons command argument  or the actual text of the link button becuase this is the parameter I need to send thru the querysting to open that page.

It does not seem to get either method.
Protected Sub myRadGridFin_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGridFin.ItemCreated
        If TypeOf e.Item Is GridDataItem Then
            Dim SendDDn As String
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim img As Image = DirectCast(item.FindControl("imgPrint"), Image)
            Dim DDN As LinkButton = DirectCast(item.FindControl("lnkAdd"), LinkButton)
  
            SendDDn = DDN.CommandArgument.ToString
            "neither works"
            SendDDn = DDN.Text.ToString
  
            img.Attributes.Add("onclick", "javascript:window.open('??.aspx?DDN=" + SendDDn.ToString() & "'); return false;")
        End If
  
    End Sub

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 30 Mar 2012, 05:59 AM
Hi Kevin,

Please try the same in ItemDataBound event. ItemCreated is fired before the item is data-bound. Thus in ItemCreated no data will be available in the cells' text or input controls.

Please take a look into the following code snippet.

VB:
Protected Sub myRadGridFin_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim SendDDn As String = Nothing
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim img As Image = DirectCast(item.FindControl("imgPrint"), Image)
        Dim DDN As LinkButton = DirectCast(item.FindControl("lnkAdd"), LinkButton)
 
        SendDDn = DDN.CommandArgument.ToString()
        SendDDn = DDN.Text.ToString()
 
        img.Attributes.Add("onclick", "javascript:window.open('??.aspx?DDN=" + SendDDn.ToString() + "'); return false;")
    End If
End Sub

Regards,
-Shinu.
0
Kevin
Top achievements
Rank 1
answered on 30 Mar 2012, 03:36 PM
Hi,

ok got it, i just added it to the same event you had answered and earlier question witht teh same items.  thanks for the help.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or