Asp. Implementation of variable-level dynamic menu in net
Source: Internet
Author: User
Asp.net| Menu | The news from the yesterday, according to customer needs, according to the following table dynamically generate the following menu: The data in the table is dynamically updated.
We usually iewebcontr to do when the menu is directly in the HTML input, that is, static, now to make dynamic, and the menu series is uncertain, how to achieve it? The author found that when using iewebcontr to do menu, menu items can be entered directly, or you can specify to read a menu item from a file by using the following method:
&n BSP; The question now becomes how to modify the Menuone.txt file based on the category number of the datasheet. Place the procedure on the data table after it has been modified. The following is the generation of Menuone.txt source code based on the contents of the table:
Imports System.IO
Dim Txtwriter as StreamWriter
Txtwriter = File.createtext (Server.MapPath ("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 = "&"
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"))
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= ' Adminclass_add.aspx?classname= "& strname & "" & Strand & "Classid=" & Strid & "' target= ' main2 '/>")
' 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= ' Adminclass_add.aspx?classname= "& strname & "" & Strand & "Classid=" & Strid & "' target= ' main2 '/>")
' 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= ' Adminclass_add.aspx?classname= "& strname & "" & Strand & "Classid=" & Strid & "' target= ' main2 '/>")
' 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 ()
End Sub
Sub Creatmenuone (ByVal strpath as String)
Dim Txtwriter as StreamWriter
Txtwriter = File.createtext (strpath + ("\ ... \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 = "&"
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"))
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service