We help IT Professionals succeed at work.

ASP.net Datagrid and Hyperlink column

vmarria asked
Medium Priority
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?

Watch Question

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 snippet...it 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


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?


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks Mike -

I used a template column and it worked like a charm thanks...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.