Dynamic menu for .net

 

c# code:   
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.lbl_Menu.Text = GetMenu("9999","999"); this.lbl_UserName.Text = "Tim"; this.lbl_MacIP.Text = Page.Request.UserHostAddress; } } private string GetMenu(string UserID, string TopMenuID) { System.Data.DataSet ds = GetMenuDataSet(UserID); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("
    "); if (ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0) { System.Data.DataView dv = ds.Tables[0].DefaultView; dv.RowFilter = "MenuUppID='999'"; System.Data.DataTable dt = dv.ToTable(); for (int i = 0; i < dt.Rows.Count; i++) { System.Data.DataRow dr = dt.Rows[i]; sb.Append("
  • " + (dr[1] != null ? dr[1].ToString() : "") + ""); string subString = getSubMenu(dr[0].ToString(), dv); if (subString != "") { sb.Append(subString); } } } sb.Append("
"); return sb.ToString(); } private string getSubMenu(string MenuUppID,System.Data.DataView dv) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); dv.RowFilter = "MenuUppID='" + MenuUppID + "'"; System.Data.DataTable dt = dv.ToTable(); if (dt.Rows.Count != 0) { sb.Append(""); } return sb.ToString(); } private System.Data.DataSet GetMenuDataSet(string userID) { System.Data.DataSet ds = new System.Data.DataSet(); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("MenuName"); dt.Columns.Add("MenuUrl"); dt.Columns.Add("MenuUppID"); dt.Columns.Add("MenuSort"); System.Data.DataRow dr = dt.NewRow(); dr[0] = "0"; dr[1] = "首页"; dr[2] = "index.htm"; dr[3] = "999"; dr[4] = "1"; dt.Rows.Add(dr); System.Data.DataRow dr1 = dt.NewRow(); dr1[0] = "1"; dr1[1] = "信息中心"; dr1[2] = "a.htm"; dr1[3] = "999"; dr1[4] = "1"; dt.Rows.Add(dr1); System.Data.DataRow dr2 = dt.NewRow(); dr2[0] = "2"; dr2[1] = "信息查询"; dr2[2] = "a1.htm"; dr2[3] = "1"; dr2[4] = "2"; dt.Rows.Add(dr2); System.Data.DataRow dr3 = dt.NewRow(); dr3[0] = "3"; dr3[1] = "信息修改"; dr3[2] = "a2.htm"; dr3[3] = "1"; dr3[4] = "3"; dt.Rows.Add(dr3); System.Data.DataRow dr4 = dt.NewRow(); dr4[0] = "4"; dr4[1] = "个人信息"; dr4[2] = "a3.htm"; dr4[3] = "999"; dr4[4] = "4"; dt.Rows.Add(dr4); System.Data.DataRow dr5 = dt.NewRow(); dr5[0] = "5"; dr5[1] = "网上"; dr5[2] = "a3.htm"; dr5[3] = "999"; dr5[4] = "5"; dt.Rows.Add(dr5); ds.Tables.Add(dt); return ds; }
    


欢迎您! 您的IP:

 

 

转载于:https://www.cnblogs.com/Tim_Liu/archive/2010/11/22/1883990.html

你可能感兴趣的:(Dynamic menu for .net)