点滴积累【C#】---当前菜单所在位置(导航栏)
当前菜单所在位置(导航栏)
效果:
描述:就是你所进入菜单的路径,俗称导航。
代码:
1 private string thisPositionID = string.Empty; 2 public string ThisPositionID 3 { 4 get 5 { 6 if (Request.QueryString["ThisPositionID"] != null && Request.QueryString["ThisPositionID"] != string.Empty) 7 thisPositionID = Request.QueryString["ThisPositionID"]; 8 return thisPositionID; 9 } 10 set 11 { 12 thisPositionID = value; 13 } 14 }
1 private string thisPosition = string.Empty; 2 public string ThisPosition 3 { 4 get 5 { 6 if (ThisPositionID != string.Empty) 7 { 8 string sql = string.Format(@"SELECT a.MenuName AS MenuNameA,b.MenuName AS MenuNameB,c.MenuName AS MenuNameC,c.MenuLevel AS MenuLevelC FROM MenuManagement a 9 INNER JOIN MenuManagement b ON a.ParentMenuID=b.MenuID 10 INNER JOIN MenuManagement c ON b.ParentMenuID=c.MenuID 11 WHERE a.MenuID={0}", ThisPositionID); 12 DataSet ds = new DataSet(); 13 ERPDB.LoadDataSet(CommandType.Text, sql, ds, new string[] { "data" }); 14 if (ds.Tables["data"].Rows.Count == 1) 15 { 16 DataRow row = ds.Tables["data"].Rows[0]; 17 if (Convert.ToString(row["MenuLevelC"]) == "1") 18 { 19 thisPosition = string.Format("当前位置:{0}>>{1}", row["MenuNameB"], row["MenuNameA"]); 20 } 21 else if (Convert.ToString(row["MenuLevelC"]) == "2") 22 { 23 thisPosition = string.Format("当前位置:{0}>>{1}>>{2}", row["MenuNameC"], row["MenuNameB"], row["MenuNameA"]); 24 } 25 else if (Convert.ToString(row["MenuLevelC"]) == "3") 26 { 27 thisPosition = string.Format("当前位置:{0}>>{1}>>{2}", row["MenuNameC"], row["MenuNameB"], row["MenuNameA"]); 28 } 29 } 30 31 } 32 return thisPosition; 33 } 34 }
调用:
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!IsPostBack) 4 { 5 this.lbTip.Text = ThisPage.ThisPosition; 6 } 7 }