AdminMenu.ascx.cs
资源名称:SHOPASP.rar [点击查看]
上传用户:xiecaij
上传日期:2015-02-08
资源大小:2016k
文件大小:2k
源码类别:
百货/超市行业
开发平台:
ASP/ASPX
- namespace admin
- {
- using System;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Xml;
- /// <summary>
- /// AdminMenu 的摘要说明。
- /// </summary>
- public class AdminMenu : System.Web.UI.UserControl
- {
- protected System.Web.UI.WebControls.DataList MyList;
- private void Page_Load(object sender, System.EventArgs e)
- {
- string selectionID = Request.Params["selection"];
- if ( selectionID != null)
- {
- MyList.SelectedIndex = Int32.Parse(selectionID);
- }
- BindMenu(Session["RoleId"].ToString());
- }
- /// <summary>
- /// 从XML文件读入管理员目录的列表项目,并绑定到目录
- /// </summary>
- private void BindMenu(string roleId)
- {
- System.Xml.XmlDocument doc = new XmlDocument();
- doc.Load(Server.MapPath("AdminMenu.xml"));
- XmlNode itemNode = doc.DocumentElement;
- DataTable menuList = new DataTable();
- menuList.Columns.Add("ItemName");
- menuList.Columns.Add("ItemUrl");
- string itemName, itemUrl, itemRole;
- string []rowItem = new string[2];
- foreach (XmlNode node in itemNode)
- {
- itemRole = node.Attributes["RoleId"].Value;
- if (roleId == "2")
- {
- if ( itemRole == roleId)
- {
- itemName = node.Attributes["ItemName"].Value;
- itemUrl = node.Attributes["ItemUrl"].Value;
- rowItem[0] = itemName;
- rowItem[1] = itemUrl;
- menuList.Rows.Add(rowItem);
- }
- }
- else
- {
- itemName = node.Attributes["ItemName"].Value;
- itemUrl = node.Attributes["ItemUrl"].Value;
- rowItem[0] = itemName;
- rowItem[1] = itemUrl;
- menuList.Rows.Add(rowItem);
- }
- }
- MyList.DataSource = menuList.DefaultView;
- MyList.DataBind();
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器
- /// 修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }