ASP.net 将数据项放入转发器中
我有一个:
- 数据中继器
- 中继器中的
控件我想将一些值放入控件中。目前我有一个控件,如下所示:
<asp:Repeater runat="server" ID="ArchiveEntryRepeater">
snip
<asp:HyperLink ID="HyperLink1" ToolTip="Comment on Some Entry Title Here" runat="server" NavigateUrl="~/Blog/7/How-to-know-when-this/Comments">
<strong><%# DataBinder.Eval(Container.DataItem, "Comments")%></strong> Comments
</asp:HyperLink>
snip
</asp:Repeater>
效果很好,但我想放入
<%# DataBinder.Eval(Container.DataItem, "Title")%>
超链接的 NavigateURL 属性中。光是放进去好像不行啊!
I've got a:
- Data repeater
- Control in the repeater
And I'd like to put some values into the controls. At the moment I have a control in it as:
<asp:Repeater runat="server" ID="ArchiveEntryRepeater">
snip
<asp:HyperLink ID="HyperLink1" ToolTip="Comment on Some Entry Title Here" runat="server" NavigateUrl="~/Blog/7/How-to-know-when-this/Comments">
<strong><%# DataBinder.Eval(Container.DataItem, "Comments")%></strong> Comments
</asp:HyperLink>
snip
</asp:Repeater>
Which works fine, but I want to put
<%# DataBinder.Eval(Container.DataItem, "Title")%>
Into the NavigateURL property of the Hyperlink. Just putting it in doesn't seem to work!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将您的 NavigateURL 用撇号而不是双引号引起来,以免混淆 ASP.NET 解析器:
这可能是您的问题。
Try enclosing your NavigateURL in apostrophes instead of double quotes to not confuse the ASP.NET parser:
This might be your issue.
您始终可以使用事件 项目数据绑定。它具有一些优势,特别是在数据视图不清晰或需要某种类型的主要操作的情况下。
You can always bind on the back end using the event itemdatabound. It has some advantages especially where the data is not a neat view or needs some type of major manipulation.
另一种选择是松开该控件并将其替换为 html 锚点控件,如下所示:
一旦服务器向客户端呈现超链接,通常就没有理由将其设置为“runat='server'”。目的是导航到另一个页面,因此使用 asp:HyperLink 与 nchor 的开销被浪费了。
Another option would be to loose the control and replace it with an html anchor control like this:
Once the server renders a hyperlink to the client there is generally no reason to have it "runat='server'" . The purpose is to navigate to another page so the overhead of using an asp:HyperLink vs. an nchor is wasted.