2

Solution:

<asp:TemplateField SortExpression="Exp" HeaderText="text">
    <ItemTemplate>
        <asp:HyperLink runat="server" Text='<%# Eval("Name") %>' NavigateUrl='<%# string.Format("~/SubSite/Default.aspx?reg={0}&Source={1}", Eval("Id"), Request.Url) %>' />
    </ItemTemplate>
</asp:TemplateField>

Instead of:

<asp:HyperLinkField DataTextField="Name" DataNavigateUrlFields="Id"
                DataNavigateUrlFormatString="~\SubSite\Default.aspx?reg={0}"
                HeaderText="text" SortExpression="Exp" />

Greetings

I have a GridView containing some HyperLinkFields. What I am trying to do is to add the "&Source" query in the DataNavigateUrlFormatString when I click one of the hyperlinks.

When I do it like this: DataNavigateUrlFormatString="~\SubSite\Default.aspx?Query={0}&Source=<% Request.Url.AbsolutePath%>"

The URL I get is this: http://www.website.com/SubSite/Default.aspx?Query=702&Source=<%Request.Url.AbsolutePath%>

How do I make sure it writes the URL that I try to get through <% Request.Url.AbsolutePath%>?

Lundin
  • 195,001
  • 40
  • 254
  • 396

1 Answers1

1

Try this:

DataNavigateUrlFormatString="~\SubSite\Default.aspx?Query={0}&Source=" +Request.Url.AbsolutePath

OR This:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Find the control and set the values you need
    }
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Richard
  • 21,728
  • 13
  • 62
  • 101