通过网格视图中的超链接传递数据

本文关键字:超链接 数据 网格 视图 | 更新日期: 2023-09-27 18:37:08

我想通过网格视图中的超链接将数据从数据库列传递到另一个页面,我要传递的数据只是文本加载。 这是我的代码

<asp:HyperLinkField DataTextField="FullText" 
        DataTextFormatString="View Text" NavigateUrl="~/Abstract.aspx" 
        Target="_blank" />

这似乎可以打开正确的页面,但我不确定如何在新页面上查看文本,大多数帮助主题告诉您如何将数据传递到新的网格视图,但我只想查看页面中的数据或框或任何可以工作的东西。

谢谢

通过网格视图中的超链接传递数据

如果我的理解是正确的,您只想显示作为查询字符串传递到新页面的文本,如果这是正确的,只需读取查询字符串并将其显示在标签中。

为了使其正常工作,您需要在网格内的链接中指定查询字符串,您的链接必须看起来像这样;

~/Abstract.aspx?d=your+text

在数据网格中:

    <asp:TemplateColumn>
        <ItemTemplate>
            <asp:HyperLink
                NavigateUrl='<%# "~/Abstract.aspx?d=" + HttpUtility.UrlEncode(DataBinder.Eval(Container, "DataItem.Id").ToString()) %>' 
                runat="server"
                Text="Product" />
        </ItemTemplate>
    </asp:TemplateColumn>

在目标页面中,您将得到如下内容:

string text = string.Empty;
if (this.Request.QueryString["d"] == null)
   text = "Not found";
else
   text = Server.UrlDecode(this.Request.QueryString["d"]);
// encode the text to avoid XSS (cross-site scripting)
this.myLabel.Text = Server.HtmlEncode(text);

在网格上

<asp:HyperLinkField DataTextField="FullText" 
    DataTextFormatString="View Text" 
    NavigateUrl='<%# "~/Abstract.aspx?ft=" +  System.Web.HttpUtility.UrlEncode(Eval("FullText").ToString() %>'
    Target="_blank" />

在您想要阅读的页面上,您将拥有的参数

string fullText = Request.QueryString["ft"];
if (string.IsNullOrEmpty(fullText))
{
    fullText = HttpUtility.UrlDecode(fullText);
}

您可能希望通过查询字符串传递键参数以提取要查看的数据。

如果这不是您想要的,请使您的问题更具解释性。

您可以在会话或查询字符串 ( Abstract.aspx?textid=1 ) 中传递 ID。在页面加载事件中读取此 ID 从数据库获取数据并显示。