Solved

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

Posted on 2009-05-12
11
617 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:GordJones
11 Comments
 
LVL 13

Expert Comment

by:drypz
Comment Utility
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" 

        onrowdatabound="GridView1_RowDataBound">

        <Columns>

            <asp:TemplateField HeaderText="Link">

                <ItemTemplate>

                    <asp:HyperLink ID="HyperLink1" runat="server" />

                </ItemTemplate>

            </asp:TemplateField>

        </Columns>

    </asp:GridView>
 

.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

0
 

Author Comment

by:GordJones
Comment Utility
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.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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.
0
 

Author Comment

by:GordJones
Comment Utility
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?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:GordJones
Comment Utility
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

0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
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?
0
 

Author Comment

by:GordJones
Comment Utility
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" 

        DataSourceID="odsGridDS" 

        PageSize="15" Width="100%" DataKeyNames="ASSETID" EmptyDataText="No records found!">

        <Columns>

            <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>

            <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

0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
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")
0
 

Author Closing Comment

by:GordJones
Comment Utility
This was the answer I was looking for "Can not use it because it is a button, not a link".
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now