• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1120
  • Last Modified:

ASP.net 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?



0
vmarria
Asked:
vmarria
  • 2
  • 2
1 Solution
 
ArgblatCommented:
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

-Mike
0
 
BrentxhangeCommented:
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
0
 
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]) ;
                  }
      </script>



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>
                        <Columns>
                              <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>
                        </Columns>
                  </asp:DataGrid>

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

0
 
ArgblatCommented:
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()
{
     if(!IsPostBack)
     {
          btnSubmit.Attributes.Add("onclick", "btnSubmit_ClientClick();");
     }

}

Perhaps this can lead you towards the road to enlightenment?

-Mike
0
 
vmarriaAuthor Commented:
Thanks Mike -

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now