Solved Datagrid and Hyperlink column

Posted on 2006-03-28
Last Modified: 2007-12-19
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?

Question by:vmarria
    LVL 5

    Expert Comment

    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

    LVL 3

    Expert Comment

    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

    Author Comment

    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.

    LVL 5

    Accepted Solution

    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?


    Author Comment

    Thanks Mike -

    I used a template column and it worked like a charm thanks...

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now