Genny Saxo
Genny Saxo

Reputation: 35

Pass data via hyperlink in gridview

I would like to pass data from a database column to another page via a hyperlink in the gridview, the data i want to pass is just a load of text. this is the code i have

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

This appears to work as far as opening up the correct page, but im unsure as to how to view the text on the new page, most help topics tell you how to pass the data to a new grid view, but i would just like to view the data within the page or a box or whatever will work.

Thanks

Upvotes: 0

Views: 2667

Answers (4)

Jupaol
Jupaol

Reputation: 21365

If my understanding is correct you just want to display the text passed as a query string to the new page, if this is correct, just read the query string and display it in a label.

In order for this to work, you need to specify the query string in the link inside your grid, your link would have to look something like;

~/Abstract.aspx?d=your+text

In your datagrid:

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

In the target page you would have something like:

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

Upvotes: 4

Claudio Redi
Claudio Redi

Reputation: 68400

On the grid

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

On the page you want to read the param you would have

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

Upvotes: 2

C-Sharp
C-Sharp

Reputation: 56

You can pass ID in session or in query string (Abstract.aspx?textid=1). Read this id in page load event get data from database and display.

Upvotes: 0

Mark Adesina Omoniyi
Mark Adesina Omoniyi

Reputation: 449

You might want to pass a key parameter through querystring to pull data you want to view.

If that is not what you want please make your question more explanatory.

Upvotes: 0

Related Questions