protected void GetTypelist()
{
//分类id=0表示根分类,最上级分类
GetTypeByparent("0",0);
}
protected void GetTypeByparent(string parenttypeid,int depth)
{
string padsapce = " ";
bool ishavesub = false;
DataSet ds = new DataSet();
Gametita.BLL.ArticleType bll = new Gametita.BLL.ArticleType();
ds = bll.GetList(1000, "parenttypeid='" + parenttypeid + "'", " Typeid desc");
if (ds != null)
{
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
string text = new string('*',depth*8);
TypeList += text + dt.Rows[i]["typename"].ToString() + "****<a href='articletype.aspx?parenttypeid=" + dt.Rows[i]["TypeID"].ToString() + "'>添加子分类</a>";
ishavesub = GetChildType(dt.Rows[i]["typeid"].ToString());
if (ishavesub)
{
TypeList += "<br>";
}
else
{
//没有子分类则可以删除
TypeList += "****<a href='articletypedel.aspx?typeid=" + dt.Rows[i]["TypeID"].ToString() + "' οnclick='javascript:confirm(真要删除该分类)'>删除分类</a><br>";
}
TypeList = TypeList.Replace("*", " ");
GetTypeByparent(dt.Rows[i]["typeid"].ToString(), depth + 1);
}
dt.Dispose();
dt = null;
}
}
ds = null;
}
/// <summary>
/// 检查是否有子分类
/// </summary>
/// <param name="parenttypeid"></param>
/// <returns></returns>
protected bool GetChildType(string parenttypeid)
{
bool ishave = false;
DataSet ds = new DataSet();
Gametita.BLL.ArticleType bll = new Gametita.BLL.ArticleType();
ds = bll.GetList(1, "parenttypeid='" + parenttypeid + "'", " Typeid desc");
if (ds != null)
{
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
ishave = true;
}
dt.Dispose();
dt = null;
}
}
return ishave; }

上面是列表树形分类的代码,前台输出Typelist即可,添加,删除的方法就很简单了。。。