ASP.. NET使用图像代替超链接
本文关键字:超链接 图像 NET ASP | 更新日期: 2023-09-27 17:53:52
我有一个名为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>
背后的代码:
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();
}
现在打开我的默认设置。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>
最后,当我点击这张图片时,我想导航到那个确切的回顾:
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString()
一切工作正常与asp:HyperLink
-s,但相反,我想使用图像。
我在读《ASP入门》。NET 4.5 c#和VB,在这里你可以看到所有的评论http://aspnet45.planetwrox.com/Reviews/All.aspx。我想用图像代替超链接
HyperLink
控件已经提供了此功能-它具有ImageUrl属性,并且当设置此属性时,HyperLink
显示为图像:
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString() %>'
ImageUrl="~/url/to/image" />