How to add "& Source" to DataNavigateUrlFormatString?

Decision:

<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:

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

Hi

I have a GridView containing some HyperLinkFields. What I'm trying to do is add the "& Source" request to 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 the following: http://www.website.com/SubSite/Default.aspx?Query=702&Source=<%Request.Url.AbsolutePath%>

How can I make sure it writes the URL that I am trying to go through <% Request.Url.AbsolutePath%> ?

+2
source share
1 answer

Try the following:

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

Or that:

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Find the control and set the values you need } } 
+1
source

Source: https://habr.com/ru/post/916651/


All Articles