asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

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


发布日期:2023年04月29日
 
ASP.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()

上一篇:ASP.NET实现类似Excel的数据透视表

下一篇:ASP.NET基于TCP的网络通信程序演示