Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用新弹出窗口gridview中的超链接字段链接回主页_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何使用新弹出窗口gridview中的超链接字段链接回主页

C# 如何使用新弹出窗口gridview中的超链接字段链接回主页,c#,asp.net,gridview,C#,Asp.net,Gridview,我已经创建了一个带有按钮的页面,可以打开一个新页面,如果您愿意,可以弹出一个窗口 btnToolbarSearch.Attributes.Add("onclick", "window.open('DagbokSearch.aspx','','height=600,width=600');return false"); 在这个打开的新页面上,我有一个gridview,您可以从中获得以下信息。(您可以搜索从“开始日期”到“结束日期”之间的记录。) 第一栏写着“Gåtill”是一个链接 <a

我已经创建了一个带有按钮的页面,可以打开一个新页面,如果您愿意,可以弹出一个窗口

btnToolbarSearch.Attributes.Add("onclick", "window.open('DagbokSearch.aspx','','height=600,width=600');return false");
在这个打开的新页面上,我有一个gridview,您可以从中获得以下信息。(您可以搜索从“开始日期”到“结束日期”之间的记录。)

第一栏写着“Gåtill”是一个链接

<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+"";
         }
    }

您可以在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弹出窗口。这样,您就不必离开当前页面,转到新选项卡。这将解决您的问题,并避免弹出窗口拦截器的问题


这里有一些例子:

我不确定你的要求是否能实现。我建议您使用浮动div弹出窗口。这样,您就不必离开当前页面,转到新选项卡。这将解决您的问题,并避免弹出窗口拦截器的问题

这里有一些例子:

使用这个

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();";
     }
}
用这个

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);单击超链接即可转到客户端。window.location.replace(url)将重新加载页面

btnToolbarSearch.Attributes.Add("onclick", "var windowHandle = window.open('DagbokSearch.aspx','','height=600,width=600');return false");
在超链接CLINT侧单击

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

您可以设置JavaScript:window.location.replace(url);单击超链接即可转到客户端。window.location.replace(url)将重新加载页面

btnToolbarSearch.Attributes.Add("onclick", "var windowHandle = window.open('DagbokSearch.aspx','','height=600,width=600');return false");
在超链接CLINT侧单击

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

您应该能够使用该属性获取对父窗口的引用。然后可以将其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();
        }
    });
});
//将其放在结束标记附近
//NB使用jQuery和事件委派
$(函数(){
$('table')。在('click','tr>td:first>a',函数(事件){
if(窗口开启器){
event.preventDefault();
window.opener.location.href=this.href;
window.close();
}
});
});

您应该能够使用该属性获取对父窗口的引用。然后可以将其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();
        }
    });
});
//将其放在结束标记附近
//NB使用jQuery和事件委派
$(函数(){
$('table')。在('click','tr>td:first>a',函数(事件){
if(窗口开启器){
event.preventDefault();
window.opener.location.href=this.href;
window.close();
}
});
});

根据我的经验,弹出窗口将被阻止。我建议您尝试使用fancybox作为弹出窗口(iframe模式)。在这种情况下,你的url将使你回到原来的窗口。我的经验是,弹出窗口将被阻止。我建议您尝试使用fancybox作为弹出窗口(iframe模式)。在这种情况下,您的url将使您返回到原始窗口。这并不能解决链接单击应关闭弹出窗口并重定向上一个窗口的问题。没有问题,您可以调用javascript函数来执行此操作,如函数RedirectAndClose(url){window.href.location=url;window.open(“,”\u self)”,“”);window.close();}这并不能解决链接单击应关闭弹出窗口并重定向上一个窗口的问题。没问题,您可以调用javascript函数来完成此操作,如函数RedirectAndClose(url){window.href.location=url;window.open(“,”self“,”);window.close();}