论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp.net教程
Tag:静态页面,treeview,gridview,repeater,dataset,sqldatareader,ado.net,上传,三层,ajax,xml,留言本,新闻发布,商城,注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,触发器,socket,form认证,登录,视频教程

ASP.NET中不定级动态菜单的实现

文章类别:Asp.net | 发表日期:2008-10-5 22:14:11

作者:xiangwa  出处:CSDN

 前日,根据客户需要,要根据如下的表动态生成如下的菜单:表中的数据是动态更新的。 

  我们平时IEWebContr来做菜单时都是在html中直接输入,也就是说是静态的,现在要做成动态的,而且菜单级数不定,怎么来实现呢?笔者通过研究发现,用IEWebContr来做菜单时,菜单项可以直接输入,也可以用如下的方法指定从某一个文件中读取菜单项:

   <iewc:TreeView runat="server" ID="Treeview1" NAME="Treeview1">
  <iewc:TreeNode id="Treenode1" runat="server" TreeNodeSrc="menuone.txt" Expanded="True" Text="信息类别列表"></iewc:TreeNode>
  </iewc:TreeView>
 
  其中menuone.txt的内容如下:

   <TREENODES>
  <treenode text='蔬菜' NavigateUrl='xxcb_add.aspx?classname=蔬菜&classid=01'? Target='main1'>
  <treenode text='白菜' NavigateUrl='xxcb_add.aspx?classname=白菜&classid=0101'?? Target='main1'/>
  <treenode text='萝卜' NavigateUrl='xxcb_add.aspx?classname=萝卜&classid=0102'?? Target='main1'/>
  <treenode text='黄花菜' NavigateUrl='xxcb_add.aspx?classname=黄花菜&classid=0103'?? Target='main1'/>
  </treenode>
  <treenode text='水果' NavigateUrl='xxcb_add.aspx?classname=水果&classid=02'? Target='main1'>
  <treenode text='苹果' NavigateUrl='xxcb_add.aspx?classname=苹果&classid=0201'? Target='main1'>
  <treenode text='红富士' NavigateUrl='xxcb_add.aspx?classname=红富士&classid=020101'?? Target='main1'/>
  <treenode text='其它苹果' NavigateUrl='xxcb_add.aspx?classname=其它苹果&classid=020102'?? Target='main1'/>
 
   </treenode>
  <treenode text='桃子' NavigateUrl='xxcb_add.aspx?classname=桃子&classid=0202'?? Target='main1'/>
  <treenode text='荔枝' NavigateUrl='xxcb_add.aspx?classname=荔枝&classid=0203'?? Target='main1'/>
  </treenode>
  <treenode text='粮食' NavigateUrl='xxcb_add.aspx?classname=粮食&classid=03'? Target='main1'>
  <treenode text='大米' NavigateUrl='xxcb_add.aspx?classname=大米&classid=0301'?? Target='main1'/>
  <treenode text='玉米' NavigateUrl='xxcb_add.aspx?classname=玉米&classid=0302'?? Target='main1'/>
  </treenode>
  </TREENODES>
 

  现在的问题变成了如何将数据表根据“类别号”修改menuone.txt文件。将该过程放在对数据表修改后进行。下面是根据表的内容生成menuone.txt的源代码:


   Imports System.IO
  Dim txtwriter As StreamWriter
  txtwriter = File.CreateText(Server.MapPathstrpath ("\menuone.txt"))
  txtwriter.WriteLine("<TREENODES>")

  Dim objConn As OleDbConnection
  Dim objCmd As OleDbCommand
  Dim objRead As OleDbDataReader
  Dim strSQL, strDSN As String
  Dim strid, strname, strid1, strname1 As String
  Dim strand As String
  strand = "&amp;"
 
 
  Dim i, j, k, m As Integer
  i = 0
  j = 0
  k = 0
  m = 0

  strSQL = "select * from class order by classid "

  objConn = New OleDbConnection(ConfigurationSettings.AppSettings("connString"))
  objCmd = New OleDbCommand(strSQL, objConn)
  objCmd.Connection.Open()
  objRead = objCmd.ExecuteReader()

  While objRead.Read()
 
  If j = 0 Then
  j = Len(Trim(objRead.Item("classid")))
  Else
  strid = strid1
  strname = strname1
  i = Len(Trim(objRead.Item("classid")))

  k = i - j

  Select Case k
  Case Is > 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'  Target='main1'>")
  Case Is = 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'   Target='main1'/>")
  Case Is < 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'   Target='main1'/>")
  'txtwriter.WriteLine("</treenode>")

  m = k
  While m < 0
  txtwriter.WriteLine("</treenode>")
  m = m + 2
  End While

  End Select

  j = Len(Trim(objRead.Item("classid")))

  End If

  strid1 = Trim(objRead.Item("classid"))
  strname1 = Trim(objRead.Item("classname"))

  End While

   'strid = strid1
  'strname = strname1
  i = Len(strid)
  k = j - i
  strid = strid1
  strname = strname1
  Select Case k
  Case Is > 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'   Target='main1'/>")
  'txtwriter.WriteLine("</treenode>")

  m = Len(strid) / 2

  While m > 1
  txtwriter.WriteLine("</treenode>")
  m = m - 1
  End While
  Case Is = 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'   Target='main1'/>")
  'txtwriter.WriteLine("</treenode>")
  m = Len(strid) / 2

  While m > 1
  txtwriter.WriteLine("</treenode>")
  m = m - 1
  End While
  Case Is <= 0
  txtwriter.WriteLine("<treenode text='" & strname & "' NavigateUrl='xxcb_add.aspx?classname=" & strname & "" & strand & "classid=" & strid & "'   Target='main1'/>")
  'txtwriter.WriteLine("</treenode>")

  m = Len(strid) / 2

  While m > 1
  txtwriter.WriteLine("</treenode>")
  m = m - 1
  End While

  End Select
  txtwriter.WriteLine("</TREENODES>")
  txtwriter.Close()
 

  这样menuone.txt就按要求生成了菜单源文件。

视频教程列表
文章教程搜索
 
Asp.net推荐教程
Asp.net热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058