首页 > 代码库 > asp.net二级菜单导航 实例
asp.net二级菜单导航 实例
.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default17.aspx.cs" Inherits="Default17" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src=http://www.mamicode.com/"jquery-1.8.3.js" type="text/javascript"></script>>.aspx.cs代码如下:using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.OleDb; public partial class Default17 : System.Web.UI.Page { string str_cnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="; string str_sourcefile = "mdb\\mydb.mdb"; OleDbConnection cnn; OleDbCommand cmd; OleDbDataReader datar; string str_sql; protected void Page_Load(object sender, EventArgs e) { makenav(); } protected void makenav() { string str_conn = str_cnn + MapPath(str_sourcefile); cnn = new OleDbConnection(str_conn); cnn.Open(); str_sql = "SELECT t_menuL0.*, t_menuL1.* FROM t_menuL1 RIGHT JOIN t_menuL0 ON t_menuL1.m1_m0id = t_menuL0.m0_id"; cmd = new OleDbCommand(str_sql, cnn); datar = cmd.ExecuteReader(); Panel pnl_menuset, pnl_submenu; HyperLink a_m0, a_m1; while (datar.Read()) { string s_m0 = datar["m0_id"].ToString(); pnl_menuset = (Panel)div_menu.FindControl("div_menuset_"+s_m0); if (pnl_menuset == null) { pnl_menuset = new Panel(); pnl_menuset.CssClass = "menuset"; pnl_menuset.ID = "div_menuset_" + s_m0; div_menu.Controls.Add(pnl_menuset); } pnl_menuset = (Panel)div_menu.FindControl("div_menuset_" + s_m0); a_m0 = (HyperLink)FindControl("a_m0_"+s_m0); if (a_m0 == null) { a_m0 = new HyperLink(); a_m0.CssClass = "m0"; a_m0.ID = "a_m0_" + s_m0; a_m0.Text = datar["m0_ttl"].ToString(); a_m0.NavigateUrl = datar["m0_url"].ToString(); pnl_menuset.Controls.Add(a_m0); } if (!(datar["m1_ttl"] is DBNull)) { pnl_submenu = (Panel)FindControl("div_submenu_" + s_m0); if (pnl_submenu == null) { pnl_submenu = new Panel(); pnl_submenu.CssClass = "submenu"; pnl_submenu.ID = "div_submenu_" + s_m0; pnl_menuset.Controls.Add(pnl_submenu); } pnl_submenu = (Panel)FindControl("div_submenu_" + s_m0); a_m1 = new HyperLink(); a_m1.CssClass = "m1"; a_m1.ID = "a_m1_" + datar["m1_id"].ToString(); a_m1.Text = datar["m1_ttl"].ToString(); a_m1.NavigateUrl = datar["m1_url"].ToString(); pnl_submenu.Controls.Add(a_m1); } } cnn.Close(); Panel p = new Panel(); p.Style.Add("clear", "both"); div_menu.Controls.Add(p); } }
效果如下:
asp.net二级菜单导航 实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。