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

Hyperlinkcolumn and OnItemDataBound

2 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ulrich
Top achievements
Rank 1
Ulrich asked on 03 Sep 2010, 11:53 AM
Hello,

I use the serverside OnItemDataBound event to apply custom format condition logic.

In some columns I prefix the .Text-property of the TableCell with additional Information.

This works fine, but fails with HyperLinkColumns, as the .Text-Property only contains " ". When I know change the Text property by prefixing it with something, the actual Hyperlink is not rendered, but myprefix + " "

How can I change this behaviour?

best regards and thanks in advance

Ulrik

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Sep 2010, 12:14 PM
Hello Ulrik,

For setting new text to GridHyperLinkColumn access the Hyperlink control first and then set its text like below.

ASPX:
<telerik:GridHyperLinkColumn DataTextFormatString="Search Google for '{0}'" DataNavigateUrlFields="CompanyName" UniqueName="GridHyperLinkColumn" DataNavigateUrlFormatString="http://www.google.com/search?hl=en&q={0}&btnG=Google+Search" DataTextField="CompanyName">
</telerik:GridHyperLinkColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
  if (e.Item is GridDataItem)
   {
     GridDataItem item = (GridDataItem)e.Item;
     HyperLink link = (HyperLink)item["GridHyperLinkColumn"].Controls[0];  //accessing Hyperlink control
     link.Text =  "new text"+link.Text ; // setting new text
   }
 }

Thanks,
Princy.
0
Ulrich
Top achievements
Rank 1
answered on 03 Sep 2010, 01:51 PM
That worked like a charm, thank you very much :)
Tags
Grid
Asked by
Ulrich
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ulrich
Top achievements
Rank 1
Share this question
or