熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET中不定級動態菜單的實現

2022-06-13   來源: .NET編程 
我們平時IEWebContr來做菜單時都是在html中直接輸入也就是說是靜態的現在要做成動態的而且菜單級數不定怎麼來實現呢?筆者通過研究發現用IEWebContr來做菜單時菜單項可以直接輸入也可以用如下的方法指定從某一個文件中讀取菜單項  

<iewc:TreeView runat=server ID=Treeview NAME=Treeview
<iewc:TreeNode id=Treenode runat=server TreeNodeSrc=menuonetxt Expanded=True Text=信息類別列表
</iewc:TreeNode>
</iewc:TreeView> 
 
  其中menuonetxt的內容如下  

<TREENODES>
<treenode text=蔬菜 NavigateUrl=xxcb_addaspx?classname=蔬菜&classid=? Target=main
 <treenode text=白菜 NavigateUrl=xxcb_addaspx?classname=白菜&classid=?? Target=main/>
 <treenode text=蘿卜 NavigateUrl=xxcb_addaspx?classname=蘿卜&classid=?? Target=main/>
 <treenode text=黃花菜 NavigateUrl=xxcb_addaspx?classname=黃花菜&classid=?? Target=main/>
</treenode>
<treenode text=水果 NavigateUrl=xxcb_addaspx?classname=水果&classid=? Target=main
 <treenode text=蘋果 NavigateUrl=xxcb_addaspx?classname=蘋果&classid=? Target=main
 <treenode text=紅富士 NavigateUrl=xxcb_addaspx?classname=紅富士&classid=?? Target=main/>
<treenode text=其它蘋果 NavigateUrl=xxcb_addaspx?classname=其它蘋果&classid=?? Target=main/>  
</treenode>
 <treenode text=桃子 NavigateUrl=xxcb_addaspx?classname=桃子&classid=?? Target=main/>
 <treenode text=荔枝 NavigateUrl=xxcb_addaspx?classname=荔枝&classid=?? Target=main/>
</treenode>
<treenode text=糧食 NavigateUrl=xxcb_addaspx?classname=糧食&classid=? Target=main
 <treenode text=大米 NavigateUrl=xxcb_addaspx?classname=大米&classid=?? Target=main/>
 <treenode text=玉米 NavigateUrl=xxcb_addaspx?classname=玉米&classid=?? Target=main/>
</treenode>
</TREENODES>  

  現在的問題變成了如何將數據表根據類別號修改menuonetxt文件將該過程放在對數據表修改後進行下面是根據表的內容生成menuonetxt的源代碼  

Imports SystemIO
Dim txtwriter As StreamWriter
txtwriter = FileCreateText(ServerMapPathstrpath (\menuonetxt))
txtwriterWriteLine(<TREENODES>)
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim objRead As OleDbDataReader
Dim strSQL strDSN As String
Dim strid strname strid strname As String
Dim strand As String
strand = &  
Dim i j k m As Integer
i =
j =
k =
m =
strSQL = select * from class order by classid
objConn = New OleDbConnection(ConfigurationSettingsAppSettings(connString))
objCmd = New OleDbCommand(strSQL objConn)
objCmdConnectionOpen()
objRead = objCmdExecuteReader()
While objReadRead() 
 If j = Then
  j = Len(Trim(objReadItem(classid)))
 Else
  strid = strid
  strname = strname
  i = Len(Trim(objReadItem(classid)))
  k = i j
  Select Case k
   Case Is >
    txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main)
   Case Is =
    txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main/>)
   Case Is <
    txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main/>)
   txtwriterWriteLine(</treenode>)
   m = k
   While m <
    txtwriterWriteLine(</treenode>)
    m = m +
   End While
  End Select
  j = Len(Trim(objReadItem(classid)))
 End If 
 strid = Trim(objReadItem(classid))
 strname = Trim(objReadItem(classname))
 End While  
 strid = strid
 strname = strname
 i = Len(strid)
 k = j i
 strid = strid
 strname = strname
 Select Case k
  Case Is >
   txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main/>)
   txtwriterWriteLine(</treenode>)
   m = Len(strid) /
   While m >
    txtwriterWriteLine(</treenode>)
    m = m
   End While
  Case Is =
   txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main/>)
   txtwriterWriteLine(</treenode>)
   m = Len(strid) /
   While m >
    txtwriterWriteLine(</treenode>)
    m = m
   End While
  Case Is <=
   txtwriterWriteLine(<treenode text= & strname & NavigateUrl=xxcb_addaspx?classname= & strname & & strand & classid= & strid & Target=main/>)
   txtwriterWriteLine(</treenode>)
   m = Len(strid) /
   While m >
    txtwriterWriteLine(</treenode>)
    m = m
   End While
  End Select
  txtwriterWriteLine(</TREENODES>)
 txtwriterClose()  

From:http://tw.wingwit.com/Article/program/net/201311/13797.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.