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