using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUCTechnologyPark.UIControl;
using System.Data;
using NUCTechnologyParkBLL;
namespace NUCTechnologyPark.UserControl
{
public partial class Head : BaseUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
BindMenu();
}
//从数据库查询绑定菜单
public void BindMenu()
{
int Sign = 0;
DataTable dtm = B_News.BindSignMenuName(Sign); //需修改查询出所有数据
string parentMenuFilter = "1=1";
BindMenuItems(dtm, parentMenuFilter);
}
//绑定一级栏目
public void BindMenuItems(DataTable table, string strParentNodeFilter)
{
//MenuItem DMenuNode = new MenuItem();
//DMenuNode.Text =" "+"首页";
//DMenuNode.Value = "109";
//DMenuNode.NavigateUrl = "../Default.aspx";
//DMenuNode.Enabled = true;
//DMenuNode.Selectable = true;
//this.Menu1.Items.Add(DMenuNode);
DataRow[] drs = table.Select(strParentNodeFilter);
foreach (DataRow dr in drs)
{
MenuItem MenuNode = new MenuItem();
if (dr["Menu_Pk"].ToString() == "109")
{
//Menu1.Items[0].Text = "<a style=\"你的样式\" class=\"你的class\">文本</a>";
MenuNode.Text = "首页";
MenuNode.Value = "109";
MenuNode.NavigateUrl = "../Default.aspx";
MenuNode.Enabled = true;
MenuNode.Selectable = true;
}
else
{
MenuNode.Text = dr["Class_Name"].ToString();
MenuNode.Value = dr["Menu_Pk"].ToString();
MenuNode.NavigateUrl = dr["MUrl"].ToString();
MenuNode.Enabled = true;
MenuNode.Selectable = true;
}
this.Menu1.Items.Add(MenuNode);
//设置节点是否可以选择和点击
if (dr["Menu_Pk"].ToString() != "109")
{
DataTable tab = B_News.GetKindMenuName(int.Parse(dr["Menu_Pk"].ToString())); //根据栏目Pk查询出二级栏目
AddChildMenu(MenuNode, tab);
}
}
}
//绑定二级栏目
public void AddChildMenu(MenuItem node, DataTable tab)
{
for (int i = 0; i < tab.Rows.Count; i++)
{
DataRow dr = tab.Rows[i];
MenuItem ChildNode = new MenuItem();
ChildNode.Text = "<span style=\"color:Black;Z-Index:-1;border-bottom:1px solid Menu ;display:inline-block;Border-style:none;100px;height:22px;border-bottom:1px solid Menu;padding-top:5px;\" >" + dr["Class_Name"].ToString() + "</span>";
ChildNode.Value = dr["Menu_Pk"].ToString();
ChildNode.NavigateUrl = dr["Url"].ToString();
ChildNode.Enabled = true;
ChildNode.Selectable = true;
node.ChildItems.Add(ChildNode);
//AddChildMenu(ChildNode, int.Parse(dr["Menu_Pk"].ToString()), tab);
}
}
}
}