在 Repeater 中渲染超链接控件
我有一个复读机,它与一本字典绑定在一起。虽然我可以访问超链接,但无法渲染超链接。我有这样的代码:
<%# DataBinder.Eval((System.Collections.Generic.KeyValuePair<string, HyperLink>)Container.DataItem, "Value.NavigateUrl") %>
Value.NavigateUrl
是一个测试,看看我是否可以访问该属性,我可以。输出是要链接到的超链接的 URL。我还尝试了“文本”,效果很好。这意味着它被识别为超链接,并且可以作为一个超链接进行访问,但我想将其呈现为一个超链接。我该怎么做?
I've got a repeater and it is bound to a dictionary . Although I can access the HyperLink, I can't render one. I have this code:
<%# DataBinder.Eval((System.Collections.Generic.KeyValuePair<string, HyperLink>)Container.DataItem, "Value.NavigateUrl") %>
The Value.NavigateUrl
was a test to see if I could access that property, and I can. The output is the URL the hyperlink to link to. I also tried 'Text', which worked. This means that it's recognized as a HyperLink, and can be accessed as one, but I would like to render it as one. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能有一个更优雅的解决方案,但这就是我想出的,一个调用 Hyperlink 控件的 RenderControl 方法的受保护函数。
在后面的代码中:
然后只需从中继器中调用该函数:
There may be a more elegant solution, but this is what I came up with, a protected function that calls the
RenderControl
method of the Hyperlink control.In your code behind:
Then just call that function from your Repeater:
为什么不尝试将其放在中继器中的文字控件上......这会起作用。
Why don't you try to put it on a LITERAL control in the repeater... this will work.