带有 NavigateUrl 和 Eval() 的超链接。错误在哪里?
首先,我在 Page_Load()
的代码隐藏中更改了 HyperLink.NavigateUrl
。
但是当我决定在设计中使用 Eval()
方法来完成它之后。
<asp:HyperLink runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />
或者
<asp:HyperLink ID="urlRefuse" runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
其中 id
和 type
- 是来自 Request
的变量。
但这不起作用。仅显示原始文本“拒绝”。我的错误在哪里?提前致谢。
First I was changing HyperLink.NavigateUrl
in code-behind on Page_Load()
.
But after I decided to do it in design using Eval()
method.
<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
.
But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这很好用
this is working great
这对我有用
This worked for me
尝试在浏览器中查看Source,href 中向客户端呈现的内容是什么?是你所期望的吗?如果您尝试使用请求集合中的变量,则无法使用 Eval,您需要使用请求查询字符串参数。
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.
试试这个:
Try this:
试试这个:
Try this one:
试试这个它对我有用:
Try this it worked for me: