The previous day, based on the customer's needs, the following menu should be dynamically generated based on the following table: The data in the table is dynamically updated.
We usually use iewebcontr to directly input menus in HTML, that is, static menus. Now we want to make menus dynamic, and how can we achieve them? I found through research that when using iewebcontr as a menu item, the menu item can be directly input, or you can use the following method to specify to read the menu item from a file:
|
<Iewc: Treeview runat = "server" id = "treeview1" name = "treeview1"> "〉
<Iewc: treenode id = "treenode1" runat = "server" treenodesrc = "menuone.txt" expanded = "true" text = ".txt"> </iewc: treenode> 〉
</Iewc: Treeview> 〉 |
The content of menuone.txt is as follows:
|
</Treenode> 〉
<Treenode text = 'peach 'navigateurl = 'xxcb _ add. aspx? Classname = peach & classid = 0202 '?? Target = 'main1'/> '/〉
<Treenode text = 'ly' navigateurl = 'xxcb _ add. aspx? Classname = litchi & classid = 0203 '?? Target = 'main1'/> '/〉
</Treenode> 〉
<Treenode text = 'Grain 'navigateurl = 'xxcb _ add. aspx? Classname = grain & classid = 03 '? Target = 'main1'> '〉
<Treenode text = 'Rice 'navigateurl = 'xxcb _ add. aspx? Classname = Rice & classid = 0301 '?? Target = 'main1'/> '/〉
<Treenode text = 'corn' navigateurl = 'xxcb _ add. aspx? Classname = corn & classid = 0302 '?? Target = 'main1'/> '/〉
</Treenode> 〉
</Treenodes> 〉 |
Now, the question becomes, for example, how to modify the menuone.txt file in the data table category. Modify the data table. The following figure shows the content of the dimension table that generates menuone.txt.Source code:
|
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. receivettings ("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 ()
|
In this example, menuone.txt generates the menu source file as required.