[英]ASP.NET Using Images instead HyperLinks
I have a aspx page called bookscategory.aspx
with this markup: 我有一个名为bookscategory.aspx
的aspx页面,带有以下标记:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<p>Books list</p>
</HeaderTemplate>
<ItemTemplate>
<h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Category") %>'></asp:Literal></h3>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("Reviews") %>' ItemType="ELibraryModel.Review">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Item.Title%>' NavigateUrl='<%# "../books/bookdetails.aspx?bookId=" + Item.Id.ToString() %>'>
</asp:HyperLink><br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Code behind: 后面的代码:
using (ELibraryEntities entities = new ELibraryEntities())
{
var allbooks = from books in entities.Books.Include("Reviews")
orderby books.Category
select new { books.Category, books.Reviews};
Repeater1.DataSource = allbooks;
Repeater1.DataBind();
}
Now on my Default.aspx page I have a book image: 现在在我的Default.aspx页面上,有一个书本图像:
<div class="prod_img">
<img src="../Images/asp.net_image.jpg" alt="" title="" border="0" /></a>
</div>
<div class="box_center">
<div class="prod_title">ASP.NET Book</div>
<p class="details">ASP.NET Book.</p>
<a href="bookscategory.aspx" class="more">- read more -</a>
<div class="clear"></div>
</div>
Finally, when I click on this image I want to navigate to that exact review: 最后,当我单击该图像时,我想导航到该确切的评论:
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString()
Everything works fine with asp:HyperLink
-s but instead I want to use images. 使用asp:HyperLink
-s一切正常,但是我想使用图像。
I'm reading Beginning ASP.NET 4.5 in C# and VB and here you can see all reviews http://aspnet45.planetwrox.com/Reviews/All.aspx . 我正在阅读C#和VB中的Beginning ASP.NET 4.5,在这里您可以看到所有评论http://aspnet45.planetwrox.com/Reviews/All.aspx 。 I want to use Images instead HyperLinks. 我想使用图像而不是超链接。
HyperLink
control already provides this capabilty - it has ImageUrl property, and when this is set, HyperLink
appears as an image: HyperLink
控件已经提供了此功能-它具有ImageUrl属性,并且在设置此属性后, HyperLink
显示为图像:
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString() %>'
ImageUrl="~/url/to/image" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.