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

How to set a 'OnClick' event for GridHyperLinkColumn in RadGrid

2 Answers 620 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raj
Top achievements
Rank 1
Raj asked on 17 Jan 2014, 06:20 AM
Hi all, I am looking to set a OnClick event for GridHyperLinkColumn and I don't want to use any AJAX calls. The event should be handled in server side. So is there a way to do this?

One way would be by using AJAX . Can we achieve this in any other way?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Jan 2014, 07:59 AM
Hi Raj,

I'm afraid there is no other way since the GridHyperLinkColumn is rendering HyperLink control which does not postback and thus it does not have Click event. If you want to have a client-side click event you could access the HyperLink in the code behind and attach its onclick event as follows:

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
  {
    GridDataItem dataItem = (GridDataItem)e.Item;
    HyperLink hlnk = (HyperLink)dataItem["CustomerID"].Controls[0]; 
    hlnk.Attributes.Add("OnClick", "LinkOnClick('" + dataItem.ItemIndex + "')");
  }
}

If you want to have server-side Click event you should use GridTemplateColumn with LinkButton inside its ItemTemplate or your could use GridButtonColumn with ButtonType set to LinkButton.

Thanks,
Princy
0
Raj
Top achievements
Rank 1
answered on 17 Jan 2014, 12:30 PM
Hi Prince,

            Thanks, I just wanted to know this.

Thanks,
Raj Reddy
Tags
Grid
Asked by
Raj
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Raj
Top achievements
Rank 1
Share this question
or