views:

34

answers:

1

I have an issue where my Hyperlink field in Asp.net GridView is not accepting Javascript function that will open a popup dialog.

I am using the following snippet

 <asp:GridView ....
.
.
 <asp:HyperLinkField DataTextField="SomeColumn" HeaderText="Some Column Text" SortExpression="SomeColumn"
HeaderStyle-HorizontalAlign="Left" DataNavigateUrlFormatString="javascript:LaunchSomePopupdialog({0})"
DataNavigateUrlFields="Id" ItemStyle-Font-Underline="true">

.
.
 </asp:GridView>  

However, when I use a page url, it works: E.g.

DataNavigateUrlFormatString="~/SomeOtherPage.aspx?Id={0}"

Is there a way I can make this work with my Javascript function?

A: 

I think you have to change it to a normal tag inside of a template field without using the asp:hyperlinkfield. Then you can do something like this:

<asp:TemplateField HeaderText="Some Column Text" ItemStyle-Font-Underline="true">
    <ItemTemplate>
<a href="#" onClick="javascript:LaunchYourStuff('<%#eval("YourColumnID")')><%#eval("YourColumnDisplayText")%></a>
     </ItemTemplate>
</asp:TemplateField>

All of your asp:hyperlinkfield attributes get placed on the templateField tag.

EDIT

You cannot place javascript in the hyperlinkfield, as this is by design

Tommy