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

"Open in New Tab" doesn't work for my GridView/DataView controls

When I right-click a CommandField link in a GridView/DataView control on my ASP.NET page the "Open in New Tab" doesn't work. I stay in the same browser window.
1 Solution
Hi! Create an item template for your gridview and add an Hyperlink control. Something like...
.aspx page
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            <asp:TemplateField HeaderText="Link">
                    <asp:HyperLink ID="HyperLink1" runat="server" />
.cs file
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            HyperLink hl = (HyperLink) e.Row.FindControl("HyperLink1");
            hl.Text = e.Row.Cells[0].Text; //you can set your hyperlink text here
            hl.NavigateUrl = "http://www.yahoo.com"; //destination page when hyperlink is clicked

Open in new window

GordJonesAuthor Commented:
I guess I was looking for a reason/explaination as to why the default CommandField link option doesn't operate as expected and how to make it act as expected.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
from what I know, the "open in new tab" behaviour cannot be controlled from the server, only in the client's browser settings...
please double-check those settings.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

GordJonesAuthor Commented:
My Internet Expoler settings are set for Tabbed Browsing and to open new links in new tabs. Tried some other settings, no different. Any other ideas out there?
GordJonesAuthor Commented:
My code in the gridview is:
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Response.Redirect("DETAIL.ASPX?AssetID=" & GridView1.SelectedValue.ToString)
    End Sub

Open in new window

HainKurtSr. System AnalystCommented:
can you please submit the related html code from the browser here or give us a working URL, so we can check the page and give you some suggestions... can you use "open in a new tab" for other pages?
GordJonesAuthor Commented:
Yes I can "Open in a new tab" for links that are not in the Gridview.
The page is on an Intranet.
The code I posted previously was from the aspx.vb. I will post the gridview code from the aspx file (the link is the first column "Details")

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
        PageSize="15" Width="100%" DataKeyNames="ASSETID" EmptyDataText="No records found!">
            <asp:CommandField SelectText="Details" ShowSelectButton="True" />
            <asp:BoundField DataField="ASSETID" HeaderText="ASSETID" 
                SortExpression="ASSETID" InsertVisible="False" ReadOnly="True" 
                Visible="False" />
            <asp:BoundField DataField="ISCHILD" HeaderText="IS CHILD" 
                SortExpression="IsChild" ReadOnly="True" InsertVisible="False" >
            <ItemStyle HorizontalAlign="Center" />
            <asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" 
                SortExpression="DESCRIPTION" />
            <asp:BoundField DataField="IDENTIFICATIONNO" HeaderText="V.I.N." 
                SortExpression="IDENTIFICATIONNO" />
            <asp:BoundField DataField="LOCATION" HeaderText="LOCATION" 
                SortExpression="LOCATION" />
            <asp:BoundField DataField="INVOICENO" HeaderText="INVOICE #" 
                SortExpression="INVOICENO" />
            <asp:BoundField DataField="VENDORNAME" HeaderText="VENDOR NAME" 
                SortExpression="VENDORNAME" />
            <asp:BoundField DataField="EQUIPNO" HeaderText="EQUIP #" 
                SortExpression="EQUIPNO" />
            <asp:BoundField DataField="MODELNO" HeaderText="MODEL #" 
                SortExpression="MODELNO" />

Open in new window

HainKurtSr. System AnalystCommented:
probably you cannot use "Right Click - Open in New tab" feature, since it is not a link, but a command (think it as a button, you cannot right click on a button and open in new tab).
But If you really need to open in a new window, you may use target property (set it to "_blank")
GordJonesAuthor Commented:
This was the answer I was looking for "Can not use it because it is a button, not a link".
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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