簡體   English   中英

如何使用gridview(一個新的彈出窗口)中的超鏈接字段鏈接回我的主頁

[英]How do I use the hyperlink field in gridview, a new pop-up, to link back to my main page

我創建了一個帶有按鈕的頁面,該按鈕可以打開一個新頁面,如果可以的話,會彈出一個頁面。

btnToolbarSearch.Attributes.Add("onclick", "window.open('DagbokSearch.aspx','','height=600,width=600');return false");

在打開的這個新頁面上,我有一個gridview,您可以在其中獲取以下信息。 (您可以在“從日期”到“到日期”之間進行搜索,並獲得介於兩者之間的記錄。)

在此處輸入圖片說明

標題為“直到”的第一列是一個鏈接

<asp:HyperLinkField DataNavigateUrlFields="Foretag" 
                    DataNavigateUrlFormatString="userProfile.aspx?ID={0}" 
                    Text="Gå till" />

我希望通過此鏈接回到上一頁並打開具有相應ID的對象,但我不確定如何完成此操作。 也許有比我正在使用的方法更好的方法,但我仍在學習。

您可以在gridview的Rowdatabound事件中設置其NavigateUrl屬性。 喜歡;

protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           ((HyperLink)e.Row.Controls[1].Controls[1]).NavigateUrl = "~/userProfile.aspx?ID="+((YourType)e.Row.DataItem).ID+"";
         }
    }

我不確定您的要求是否可以解決。 我建議您改用浮動div彈出窗口。 這樣,您不必離開當前頁面並轉到新選項卡。 這樣可以解決您的問題,並且可以避免彈出窗口阻止程序出現問題。

以下是一些示例: http : //www.javascripttoolbox.com/lib/popup/example.php

用這個

protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       ((HyperLink)e.Row.Controls[1].Controls[1]).Attribute.Add("onclick", "window.opener.location =userProfile.aspx?ID="+    ((YourType)e.Row.DataItem).ID+"; window.close();";
     }
}

您可以設置JavaScript:window.location.replace(url); 到HyperLink的客戶端onclick。 window.location.replace(url)將重新加載頁面。

btnToolbarSearch.Attributes.Add("onclick", "var windowHandle = window.open('DagbokSearch.aspx','','height=600,width=600');return false");

在超鏈接cleint側onclick

hyperLink.Attributes.Add("onclick", "windowHandle.close();window.location.replace(url);return false");

您應該能夠使用window.opener屬性來獲取對父窗口的引用。 然后可以將其URL設置為選定的鏈接,然后關閉彈出窗口。

這樣的事情應該可以解決問題:

// Place this near your closing </body> tag
// NB Uses jQuery and event delegation
$(function() {        
    $('table').on('click', 'tr > td:first > a', function(event) {
        if (window.opener) {
            event.preventDefault();
            window.opener.location.href = this.href;
            window.close();
        }
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM