我们平时IEWebContr来做菜单时都是在html中直接输入,也就是说是静态的,现在要做成动态的,而且菜单级数不定,怎么来实现呢?笔者通过研究发现,用IEWebContr来做菜单时,菜单项可以直接输入,也可以用如下的方法指定从某一个文件中读取菜单项:
<iewc:TreeViewrunat="server"ID="Treeview1"NAME="Treeview1"><iewc:TreeNodeid="Treenode1"runat="server"TreeNodeSrc="menuone.txt"Expanded="True"Text="信息类别列表"></iewc:TreeNode>
</iewc:TreeView>
其中menuone.txt的内容如下:
<TREENODES><treenodetext='蔬菜'NavigateUrl='xxcb_add.aspx?classname=蔬菜&classid=01'?Target='main1'>
<treenodetext='白菜'NavigateUrl='xxcb_add.aspx?classname=白菜&classid=0101'??Target='main1'/>
<treenodetext='萝卜'NavigateUrl='xxcb_add.aspx?classname=萝卜&classid=0102'??Target='main1'/>
<treenodetext='黄花菜'NavigateUrl='xxcb_add.aspx?classname=黄花菜&classid=0103'??Target='main1'/>
</treenode>
<treenodetext='水果'NavigateUrl='xxcb_add.aspx?classname=水果&classid=02'?Target='main1'>
<treenodetext='苹果'NavigateUrl='xxcb_add.aspx?classname=苹果&classid=0201'?Target='main1'>
<treenodetext='红富士'NavigateUrl='xxcb_add.aspx?classname=红富士&classid=020101'??Target='main1'/>
<treenodetext='其它苹果'NavigateUrl='xxcb_add.aspx?classname=其它苹果&classid=020102'??Target='main1'/>
</treenode>
<treenodetext='桃子'NavigateUrl='xxcb_add.aspx?classname=桃子&classid=0202'??Target='main1'/>
<treenodetext='荔枝'NavigateUrl='xxcb_add.aspx?classname=荔枝&classid=0203'??Target='main1'/>
</treenode>
<treenodetext='粮食'NavigateUrl='xxcb_add.aspx?classname=粮食&classid=03'?Target='main1'>
<treenodetext='大米'NavigateUrl='xxcb_add.aspx?classname=大米&classid=0301'??Target='main1'/>
<treenodetext='玉米'NavigateUrl='xxcb_add.aspx?classname=玉米&classid=0302'??Target='main1'/>
</treenode>
</TREENODES>
ImportsSystem.IO
DimtxtwriterAsStreamWriter
txtwriter=File.CreateText(Server.MapPathstrpath("/menuone.txt"))
txtwriter.WriteLine("<TREENODES>") DimobjConnAsOleDbConnection
DimobjCmdAsOleDbCommand
DimobjReadAsOleDbDataReader
DimstrSQL,strDSNAsString
Dimstrid,strname,strid1,strname1AsString
DimstrandAsString
strand="&"
Dimi,j,k,mAsInteger
i=0
j=0
k=0
m=0
objCmd=NewOleDbCommand(strSQL,objConn)
objCmd.Connection.Open()
objRead=objCmd.ExecuteReader() WhileobjRead.Read()
Ifj=0Then
j=Len(Trim(objRead.Item("classid")))
Else
strid=strid1
strname=strname1
i=Len(Trim(objRead.Item("classid")))
CaseIs>0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'>")
CaseIs=0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'/>")
CaseIs<0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'/>")
'txtwriter.WriteLine("</treenode>") m=k
Whilem<0
txtwriter.WriteLine("</treenode>")
m=m+2
EndWhile EndSelect j=Len(Trim(objRead.Item("classid"))) EndIf strid1=Trim(objRead.Item("classid"))
strname1=Trim(objRead.Item("classname")) EndWhile 'strid=strid1
'strname=strname1
i=Len(strid)
k=j-i
strid=strid1
strname=strname1
SelectCasek
CaseIs>0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'/>")
'txtwriter.WriteLine("</treenode>") m=Len(strid)/2 Whilem>1
txtwriter.WriteLine("</treenode>")
m=m-1
EndWhile
CaseIs=0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'/>")
'txtwriter.WriteLine("</treenode>")
m=Len(strid)/2 Whilem>1
txtwriter.WriteLine("</treenode>")
m=m-1
EndWhile
CaseIs<=0
txtwriter.WriteLine("<treenodetext='"&strname&"'NavigateUrl='xxcb_add.aspx?classname="&strname&""&strand&"classid="&strid&"'Target='main1'/>")
'txtwriter.WriteLine("</treenode>") m=Len(strid)/2 Whilem>1
txtwriter.WriteLine("</treenode>")
m=m-1
EndWhile EndSelect
txtwriter.WriteLine("</TREENODES>")
txtwriter.Close()
这样menuone.txt就按要求生成了菜单源文件。