Link to home
Start Free TrialLog in
Avatar of pwerstreak
pwerstreak

asked on

Gridview: How to add a HyperLinkField to a TemplateField in CODE?

Could you give me an example on how I'd go about dynamically creating a TemplateField with a HyperLinkField added into it...the TemplateField would then get added to a column in the GridView...? It turns out the TemplateField's ItemTemplate can only be assigned an ITemplate, and the HyperLinkField does not implement that interface. I am looking for code, not tags in the aspx page.

The DataNavigateUrlFormatString property in HyperLinkField cannot be assigned a value with ":", forexample if you wish to add "javascript:MyFunc();", and Microsoft gives the above solution as a workaround...

Appreciate it...Thanks!
Avatar of sandip132
sandip132
Flag of Japan image

ASKER CERTIFIED SOLUTION
Avatar of sandip132
sandip132
Flag of Japan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KarinLoos
KarinLoos

I gave him 2 links with examples on dynamic templates.
Sandip explained the hyperlink column.  My suggestion is if participant doesnt respond to split points.
Avatar of pwerstreak

ASKER

I was looking for a solution (C#) that allowed me to call a jscript function with "javascript:MyFunc();" when user clicks on the HyperLink... the "for example" part may have thrown you off.

My points go to Sandip even though he doesn't provide a solution for the "javacript:" issue...

KarinLoos, I was not looking for a general way to dynamically add columns to a datagrid (specifically TemplateField with a HyperLinkField).