Datagrid and Hyperlink column

I have a datagrid that has a hyperlink cloumn.

Currently when you click on the hyperlink it loads the page in the same frame that the original page was in.

I have a javascript on the page that i would like to call when a user clicks on the hyperlink column. Is there a way to do this?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It depends on how you are creating the datagrid and hyperlink column in the first place (Visual Studio, Dreamweaver..Code Behind...Inline...etc)

Could you provide a code will get your question answered quicker, and more precise to your needs

You can use HTML and use a code like this:
<a href="YOUR PAGENAME" target="_blank">Open Your Page</a>

Your button would look like This:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="YOUR PAGE" Target=_blank Text="Link"></asp:HyperLink>

Good Luck
vmarriaAuthor Commented:
here is the script i want to call:

<script language="jscript" defer>
                  function openLocation(arrayWindow) {
                        window.document.all('2k3WindowsObject').createWindow(arrayWindow[0], arrayWindow[1], arrayWindow[2], arrayWindow[3], arrayWindow[4], arrayWindow[5]) ;

here is how i create the datagrid.
<asp:DataGrid id="Top_N_List2" runat="server" AutoGenerateColumns="False" Width="100%" BorderWidth="1px" BorderStyle="Outset">
                        <AlternatingItemStyle CssClass="altRow"></AlternatingItemStyle>
                        <ItemStyle CssClass="Row"></ItemStyle>
                        <HeaderStyle CssClass="Header"></HeaderStyle>
                              <asp:HyperLinkColumn Headertext="Cusip #" DataTextField="Security_id" DataNavigateUrlField="Security_id" DataNavigateUrlFormatString="securityedit.aspx?Sid={0}"></asp:HyperLinkColumn>
                              <asp:BoundColumn DataField="bberg_id" HeaderText="Bloomberg Id"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Total" HeaderText="Amount" DataFormatString="{0:c}"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Per" HeaderText="Percentage"></asp:BoundColumn>

The only code behind that i have is the databind option to the datagrid. let me know if you need that.

I have two thoughts...neither are the exact solution, but perhaps one or both can help you figure it out

The first is that you could perhaps switch from a HyperLinkColumn to a TemplateColumn.  Then you can just make everything HTML (including the Javascript call).  The problem with a template column becomes calling up your bound data.  From what I remember you do it using something like <%# DataBinder.Eval(Container.DataItem,"Data_Name") %>

The second thought is how you would attach a Javascript event to a vanilla ASP.NET control (like a button).  
In the code behind you would have something like this

Page_Load method()
          btnSubmit.Attributes.Add("onclick", "btnSubmit_ClientClick();");


Perhaps this can lead you towards the road to enlightenment?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vmarriaAuthor Commented:
Thanks Mike -

I used a template column and it worked like a charm thanks...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.