解决方法:
<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>
代替:
<asp:HyperLinkField DataTextField="Name" DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="~\SubSite\Default.aspx?reg={0}"
HeaderText="text" SortExpression="Exp" />
问候
我有一个包含一些 HyperLinkField 的 GridView。我想要做的是在 DataNavigateUrlFormatString
中添加“&Source”查询当我单击其中一个超链接时。
当我这样做时:DataNavigateUrlFormatString="~\SubSite\Default.aspx?Query={0}&Source=<% Request.Url.AbsolutePath%>"
我得到的 URL 是这样的:http://www.website.com/SubSite/Default.aspx?Query=702&Source=<%Request.Url.AbsolutePath%>
我如何确保它写入我尝试通过 <% Request.Url.AbsolutePath%>
获得的 URL ?
最佳答案
试试这个:
DataNavigateUrlFormatString="~\SubSite\Default.aspx?Query={0}&Source=" +Request.Url.AbsolutePath
或者这个:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Find the control and set the values you need
}
}
关于c# - 如何将 "&Source"添加到 DataNavigateUrlFormatString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5949860/