C# 带有 NavigateUrl 和 Eval() 的超链接。错误在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1779481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HyperLink with NavigateUrl with Eval(). Where is the mistake?
提问by abatishchev
First I was changing HyperLink.NavigateUrl
in code-behind on Page_Load()
.
首先,我HyperLink.NavigateUrl
在Page_Load()
.
But after I decided to do it in design using Eval()
method.
但是在我决定在设计中使用Eval()
方法之后。
<asp:HyperLink runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />
or
或者
<asp:HyperLink ID="urlRefuse" runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
where id
and type
- are variables from Request
.
其中id
和type
- 是来自 的变量Request
。
But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance.
但它不起作用。仅显示原始文本“拒绝”。我的错误在哪里?提前致谢。
采纳答案by Hamdy Mohamed
this is working great
这很好用
NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'
回答by Phaedrus
Try and ViewSource in your browser, what's being rendered to the client in your href? Is it what you expected?. If you are trying to use variables from the request collection you can't use Eval, you need to use the Request query string parameters.
在浏览器中尝试 ViewSource,在您的 href 中向客户端呈现什么?是你所期待的吗?。如果您尝试使用无法使用 Eval 的请求集合中的变量,则需要使用请求查询字符串参数。
<asp:HyperLink runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
回答by ACP
Try this one:
试试这个:
<asp:HyperLink ID="HyperLink2" runat="server" onclick='<%# String.Format("AcceptUser({0},{1})",Eval("UserId"), Eval("TsId")) %>' NavigateUrl="javascript:void(0)" Visible='<%# (bool)Eval("CanDelete") %>'>Accept</asp:HyperLink>
回答by ACP
Try this:
尝试这个:
HttpUtility.UrlEncode(Eval("type")
回答by ACP
Try this it worked for me:
试试这个它对我有用:
Eval("type").ToString()
回答by Etienne
This worked for me
这对我有用
NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'