28,405
社区成员
发帖
与我相关
我的任务
分享
<%@ Control Language="C#" AutoEventWireup="true"
Inherits="NopSolutions.NopCommerce.Web.Modules.HomePageProductsControl" Codebehind="HomePageProducts.ascx.cs" %>
<div class="HomePageProductGrid">
<asp:DataList ID="dlCatalog" runat="server" RepeatColumns="4" RepeatDirection="Horizontal"
RepeatLayout="Table" OnItemDataBound="dlRelatedProducts_ItemDataBound" ItemStyle-CssClass="ItemBox">
<ItemTemplate>
<div class="ProductItem">
<div class="title">
<asp:HyperLink ID="hlProduct" runat="server" />
</div>
<div class="picture">
<asp:HyperLink ID="hlImageLink" runat="server" />
</div>
<div class="price">
<asp:HyperLink ID="hlPrice" runat="server" />
</div>
<div class="details">
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</ItemTemplate>
</asp:DataList>
</div>
protected void dlRelatedProducts_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Product product = e.Item.DataItem as Product;
if (product != null)
{
string productURL = SEOHelper.GetProductURL(product);
HyperLink hlImageLink = e.Item.FindControl("hlImageLink") as HyperLink;
if (hlImageLink != null)
{
ProductPictureCollection productPictures = product.ProductPictures;
if (productPictures.Count > 0)
hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
else
hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));
hlImageLink.NavigateUrl = productURL;
}
HyperLink hlProduct = e.Item.FindControl("hlProduct") as HyperLink;
if (hlProduct != null)
{
hlProduct.NavigateUrl = productURL;
hlProduct.Text = product.Name;
}
HyperLink hlPrice = e.Item.FindControl("hlPrice") as HyperLink;
if (hlPrice != null)
{
hlPrice.Text = product.ProductVariants[0].Price.ToString();
}
}
}
}