发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using School_Entity;
using School_BLL.clsPublic;
namespace School_Web.admin
{
public partial class skyleft1 : BaiscWeb
{
public string sImagePath = "images/ico/2.gif";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallback)
{
string sql = "select * From SkyMenu where isDel='N' order by ShowID Asc,id desc";
School_BLL.SkyTools res = new School_BLL.SkyTools();
DataTable dt = res.SkyDataCreateDT(sql);
SetTree(dt);
}
}
protected void SetTree(DataTable dt)
{
this.Literal1.Text = @"<ul id=""menu"">" + GetMulList(dt, "0") + "</ul>";
}
/// <summary>
/// 加载1级菜单
/// </summary>
/// <param name="dt"></param>
/// <param name="spID"></param>
/// <returns></returns>
protected string GetMulList(DataTable dt, string spID)
{
string sReturn = "";
string sTmp = "";
string sR = @" <li class=""{0}""><a href=""javascript:c(m{3});"" id=""m{1}""><span><img src=""{4}"" align=""absMiddle""/>{2}</span></a></li>";
DataRow[] dr = dt.Select("parentid=" + spID);
string sIMG = "";
for (int i = 0; i < dr.Length; i++)
{
sIMG = this.SkyTool_DBNull(dr[i]["miOpen"]);
if (sIMG == ""){sIMG = sImagePath;}
sTmp = string.Format(sR, "L1", dr[i]["id"].ToString(), dr[i]["MName"].ToString(), dr[i]["id"].ToString(), sIMG) + "\n";
sReturn += sTmp;
sReturn += GetMulList2(dt, dr[i]["id"].ToString());
}
return sReturn;
}
/// <summary>
/// 加载2级菜单
/// </summary>
/// <param name="dt"></param>
/// <param name="spID"></param>
/// <returns></returns>
protected string GetMulList2(DataTable dt, string spID)
{
string sW = @" <ul id=""m{0}d"" style=""display:none;"" class=""U1"">";
sW = string.Format(sW, spID);
string sReturn = "";
string sTmp = "";
string sR = @" <li class=""{0}""><a href=""javascript:c(f{3});"" id=""f{1}""><span><img src=""{4}"" align=""absMiddle""/>{2}</span></a></li>" + "\n";
string sR1 = @" <li class=""{0}""><a href=""{3}"" id=""f{1}""><span><img src=""{4}"" align=""absMiddle""/>{2}</span></a></li>" + "\n";
DataRow[] dr = dt.Select("parentid=" + spID);
DataRow[] dr1;
string sIMG = "";
if (dr.Length > 0)
{
for (int i = 0; i < dr.Length; i++)
{
sIMG = this.SkyTool_DBNull(dr[i]["miOpen"]);
if (sIMG == "") { sIMG = sImagePath; }
dr1 = dt.Select("parentid=" + dr[i]["id"].ToString());
if (dr1.Length > 0)
{
sTmp = string.Format(sR, "L21", dr[i]["id"].ToString(), dr[i]["MName"].ToString(), dr[i]["id"].ToString(), sIMG) + "\n";
}
else
{
sTmp = string.Format(sR1, "L22", dr[i]["id"].ToString(), dr[i]["MName"].ToString(), this.SkyTool_DBNull(dr[i]["murl"]), sIMG) + "\n";
}
sReturn += sTmp;
sReturn += GetMulList3(dt, dr[i]["id"].ToString());
}
return sW + sReturn + "</ul>";
}
else
{
return sReturn;
}
}
/// <summary>
/// 加载3级菜单
/// </summary>
/// <param name="dt"></param>
/// <param name="spID"></param>
/// <returns></returns>
protected string GetMulList3(DataTable dt, string spID)
{
string sW = @" <ul id=""f{0}d"" style=""display:none;"">" + "\n";
sW = string.Format(sW, spID);
string sReturn = "";
string sTmp = "";
string sR = @" <li class=""{0}""><a href=""{4}"" id=""f{1}""><span><img src=""{3}"" align=""absMiddle""/>{2}</span></a></li>" + "\n";
DataRow[] dr = dt.Select("parentid=" + spID);
DataRow[] dr1;
if (dr.Length > 0)
{
string sIMG = "";
for (int i = 0; i < dr.Length; i++)
{
sIMG = this.SkyTool_DBNull(dr[i]["miOpen"]);
if (sIMG == "") { sIMG = sImagePath; }
sTmp = string.Format(sR, "L3", dr[i]["id"].ToString(), dr[i]["MName"].ToString(), sIMG,this.SkyTool_DBNull(dr[i]["murl"])) + "\n";
sReturn += sTmp;
}
return sW + sReturn + "</ul>";
}
else
{
return sReturn;
}
}
}
}
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。