may be useful
Code
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Categories;
using DataAccess.Categories;
using Utils;
using Common.Products;
using DataAccess.Products;
using SEO;
namespace Web.Modules
{
public partial class CategoryNavigation : UserControl
{
#region Classes
public class NopCommerceLi : WebControl, INamingContainer
{
public NopCommerceLi()
{
this.HyperLink = new HyperLink();
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.WriteBeginTag("span");
writer.WriteAttribute("class", this.CssClass);
if (!String.IsNullOrEmpty(this.LiLeftMargin))
{
writer.WriteAttribute("style", string.Format("margin-left: {0}px", this.LiLeftMargin));
}
writer.Write(HtmlTextWriter.TagRightChar);
this.HyperLink.RenderControl(writer);
writer.WriteEndTag("span");
}
public string LinkText
{
get
{
return this.HyperLink.Text;
}
set
{
if (value != null)
{
this.HyperLink.Text = value;
}
}
}
public HyperLink HyperLink { get; set; }
public string LiLeftMargin
{
get
{
object liLeftMargin = this.ViewState["LiLeftMargin"];
if (liLeftMargin != null)
return Convert.ToString(liLeftMargin);
return string.Empty;
}
set
{
this.ViewState["LiLeftMargin"] = value;
}
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
#region Overrides
protected override void CreateChildControls()
{
if (!this.ChildControlsCreated)
{
if (!this.ChildControlsCreated)
{
CreateMenu();
base.CreateChildControls();
ChildControlsCreated = true;
}
}
}
#endregion
#region Utilities
protected void CreateMenu()
{
CategoryCollection breadCrumb = null;
Category currentCategory = CategoryManager.GetCategoryById(CommonHelper.QueryStringInt("CategoryID"));
if (currentCategory == null)
{
Product product = ProductManager.GetProductByID(CommonHelper.QueryStringInt("ProductID"));
if (product != null)
{
ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(CommonHelper.QueryStringInt("ProductID"));
if (productCategories.Count > 0)
//currentCategory = productCategories[0].Category;
currentCategory = CategoryManager.GetCategoryById(productCategories[0].CategoryID);
}
}
if (currentCategory != null)
breadCrumb = CategoryManager.GetBreadCrumb(currentCategory.Cat_Id);
else
breadCrumb = new CategoryCollection();
CreateChildMenu(breadCrumb, 0, currentCategory, 0);
}
protected void CreateChildMenu(CategoryCollection breadCrumb, int rootCategoryID, Category currentCategory, int level)
{
int padding = level++ * 15;
foreach (Category category in CategoryManager.GetAllCategories(rootCategoryID))
{
NopCommerceLi link = new NopCommerceLi();
phCategories.Controls.Add(link);
// string categoryURL = SEOHelper.GetCategoryURL(category.Cat_Id);
string categoryURL = null;
if (currentCategory != null && currentCategory.Cat_Id == category.Cat_Id)
link.CssClass = "title";
else
link.CssClass = "title";
link.HyperLink.NavigateUrl = categoryURL;
link.HyperLink.Text = category.Cat_Name;
if (padding > 0)
link.LiLeftMargin = padding.ToString();
for (int i = 0; i <= breadCrumb.Count - 1; i++)
if (breadCrumb[i].Cat_Id == category.Cat_Id)
CreateChildMenu(breadCrumb, category.Cat_Id, currentCategory, level);
}
}
#endregion
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CategoryNavigation.ascx.cs" Inherits="Web.Modules.CategoryNavigation" %>
<!-- 左侧开始//-->
<div class="left_he">
<ul class="class_menu1">
<asp:PlaceHolder runat="server" ID="phCategories" />
<%-- <span class="title">按菜系</span>
<li>
<a href="#">家常菜</a><a href="#">清爽凉菜</a><a href="#">美味糕点</a>
<a href="#">美味粥汤</a><a href="#">药膳偏方</a><a href="#">素斋菜</a>
<a href="#">甜品/点心</a><a href="#">料理</a>
</li>
<span class="title">按功效</span>
<li><a href="#">美容养颜</a><a href="#">减肥</a><a href="#">增肥</a> <a href="#">丰胸</a><a
href="#">乌发</a><a href="#">益智补脑</a> <a href="#">清热去火</a><a href="#">补虚养身</a><a href="#">滋阴壮阳</a>
</li>
<span class="title">按口味</span>
<li><a href="#">清淡味</a><a href="#">家常味</a><a href="#">五香味</a> <a href="#">酸辣味</a><a
href="#">麻辣味</a><a href="#">重辣味</a> <a href="#">咖喱味</a><a href="#">奶香味</a> </li> --%>
</ul>
<a href="#" class="upload_botton_index">
<img src="../image/scsp_botton.jpg" /></a>
<ul class="your_favourlist">
<span class="title_blog">您可能会喜欢</span>
<li>
<img src="../image/testphoto1.gif" /><a href="#">姜葱炒海蟹</a><br />
¥36 元 </li>
</ul>
<ul class="your_favourlist">
<span class="title_blog">您的一周食物</span>
<li>
<img src="image/testphoto1.gif" /><a href="#">姜葱炒海蟹</a><br />¥36 元
</li>
</ul>
</div>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Categories;
using DataAccess.Categories;
using Utils;
using Common.Products;
using DataAccess.Products;
using SEO;
namespace Web.Modules
{
public partial class CategoryNavigation : UserControl
{
#region Classes
public class NopCommerceLi : WebControl, INamingContainer
{
public NopCommerceLi()
{
this.HyperLink = new HyperLink();
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.WriteBeginTag("span");
writer.WriteAttribute("class", this.CssClass);
if (!String.IsNullOrEmpty(this.LiLeftMargin))
{
writer.WriteAttribute("style", string.Format("margin-left: {0}px", this.LiLeftMargin));
}
writer.Write(HtmlTextWriter.TagRightChar);
this.HyperLink.RenderControl(writer);
writer.WriteEndTag("span");
}
public string LinkText
{
get
{
return this.HyperLink.Text;
}
set
{
if (value != null)
{
this.HyperLink.Text = value;
}
}
}
public HyperLink HyperLink { get; set; }
public string LiLeftMargin
{
get
{
object liLeftMargin = this.ViewState["LiLeftMargin"];
if (liLeftMargin != null)
return Convert.ToString(liLeftMargin);
return string.Empty;
}
set
{
this.ViewState["LiLeftMargin"] = value;
}
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
#region Overrides
protected override void CreateChildControls()
{
if (!this.ChildControlsCreated)
{
if (!this.ChildControlsCreated)
{
CreateMenu();
base.CreateChildControls();
ChildControlsCreated = true;
}
}
}
#endregion
#region Utilities
protected void CreateMenu()
{
CategoryCollection breadCrumb = null;
Category currentCategory = CategoryManager.GetCategoryById(CommonHelper.QueryStringInt("CategoryID"));
if (currentCategory == null)
{
Product product = ProductManager.GetProductByID(CommonHelper.QueryStringInt("ProductID"));
if (product != null)
{
ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(CommonHelper.QueryStringInt("ProductID"));
if (productCategories.Count > 0)
//currentCategory = productCategories[0].Category;
currentCategory = CategoryManager.GetCategoryById(productCategories[0].CategoryID);
}
}
if (currentCategory != null)
breadCrumb = CategoryManager.GetBreadCrumb(currentCategory.Cat_Id);
else
breadCrumb = new CategoryCollection();
CreateChildMenu(breadCrumb, 0, currentCategory, 0);
}
protected void CreateChildMenu(CategoryCollection breadCrumb, int rootCategoryID, Category currentCategory, int level)
{
int padding = level++ * 15;
foreach (Category category in CategoryManager.GetAllCategories(rootCategoryID))
{
NopCommerceLi link = new NopCommerceLi();
phCategories.Controls.Add(link);
// string categoryURL = SEOHelper.GetCategoryURL(category.Cat_Id);
string categoryURL = null;
if (currentCategory != null && currentCategory.Cat_Id == category.Cat_Id)
link.CssClass = "title";
else
link.CssClass = "title";
link.HyperLink.NavigateUrl = categoryURL;
link.HyperLink.Text = category.Cat_Name;
if (padding > 0)
link.LiLeftMargin = padding.ToString();
for (int i = 0; i <= breadCrumb.Count - 1; i++)
if (breadCrumb[i].Cat_Id == category.Cat_Id)
CreateChildMenu(breadCrumb, category.Cat_Id, currentCategory, level);
}
}
#endregion
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CategoryNavigation.ascx.cs" Inherits="Web.Modules.CategoryNavigation" %>
<!-- 左侧开始//-->
<div class="left_he">
<ul class="class_menu1">
<asp:PlaceHolder runat="server" ID="phCategories" />
<%-- <span class="title">按菜系</span>
<li>
<a href="#">家常菜</a><a href="#">清爽凉菜</a><a href="#">美味糕点</a>
<a href="#">美味粥汤</a><a href="#">药膳偏方</a><a href="#">素斋菜</a>
<a href="#">甜品/点心</a><a href="#">料理</a>
</li>
<span class="title">按功效</span>
<li><a href="#">美容养颜</a><a href="#">减肥</a><a href="#">增肥</a> <a href="#">丰胸</a><a
href="#">乌发</a><a href="#">益智补脑</a> <a href="#">清热去火</a><a href="#">补虚养身</a><a href="#">滋阴壮阳</a>
</li>
<span class="title">按口味</span>
<li><a href="#">清淡味</a><a href="#">家常味</a><a href="#">五香味</a> <a href="#">酸辣味</a><a
href="#">麻辣味</a><a href="#">重辣味</a> <a href="#">咖喱味</a><a href="#">奶香味</a> </li> --%>
</ul>
<a href="#" class="upload_botton_index">
<img src="../image/scsp_botton.jpg" /></a>
<ul class="your_favourlist">
<span class="title_blog">您可能会喜欢</span>
<li>
<img src="../image/testphoto1.gif" /><a href="#">姜葱炒海蟹</a><br />
¥36 元 </li>
</ul>
<ul class="your_favourlist">
<span class="title_blog">您的一周食物</span>
<li>
<img src="image/testphoto1.gif" /><a href="#">姜葱炒海蟹</a><br />¥36 元
</li>
</ul>
</div>