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

Assign onclientclick function on hyperlink column

1 Answer 286 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lubna Ansari
Top achievements
Rank 1
Lubna Ansari asked on 16 Jul 2010, 02:35 PM
Hi,

I am using a hyper link column in grid and assigning its url on code behind. How can I add a onclientclick event on this hyper link column?
Below is my code

 

<telerik:GridHyperLinkColumn DataTextFormatString="{0}"

 

 

DataNavigateUrlFields="Question" UniqueName="Question"

 

 

HeaderText="Question" DataTextField="Question" >

 

 

<ItemStyle Width="200px"/>

 

 

 

</telerik:GridHyperLinkColumn>

 


Assigning value in code behind

 

HyperLink hyplnkQn = (HyperLink)item["Question"].Controls[0];

 

hyplnkQn.NavigateUrl =

GeneralDeclaration.Path + GeneralDeclaration.PAGE_ServiceQuestionnaire + "?" + strQueryString;

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Jul 2010, 08:43 AM
Hello Lubna,

You can achieve this by attaching 'onclick' event to Hyperlink from code behind.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            HyperLink hyplnkQn = (HyperLink)item["Question"].Controls[0];
            hyplnkQn.Attributes.Add("onclick","hyperLinkClick();"); // attaching 'onclick' client event to HyperLink
        }
    }

Thanks,
Princy.
Tags
Grid
Asked by
Lubna Ansari
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or