Asp. Realization of dynamic menu with net variable level

Source: Internet
Author: User
Tags rand variable trim
Asp.net| Menu | Dynamic we usually iewebcontr to do when the menu is directly in the HTML input, that is, static, now to make dynamic, and 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:


 
The contents of Menuone.txt are as follows:

<TREENODES>
<treenode text= ' vegetable ' navigateurl= ' xxcb_add.aspx?classname= vegetable &classid=01 '? target= ' Main1 '
<treenode text= ' cabbage ' navigateurl= ' xxcb_add.aspx?classname= cabbage &classid=0101 '?? target= ' main1 '/>
<treenode text= ' radish ' navigateurl= ' xxcb_add.aspx?classname= radish &classid=0102 '?? target= ' main1 '/>
<treenode text= ' Day lily ' navigateurl= ' xxcb_add.aspx?classname= day lily &classid=0103 '?? target= ' main1 '/>
</treenode>
<treenode text= ' fruit ' navigateurl= ' xxcb_add.aspx?classname= fruit &classid=02 '? target= ' Main1 '
<treenode text= ' apple ' navigateurl= ' xxcb_add.aspx?classname= Apple &classid=0201 '? target= ' Main1 '
<treenode text= ' Red Fuji ' navigateurl= ' xxcb_add.aspx?classname= red Fuji &classid=020101 '?? target= ' main1 '/>
<treenode text= ' other apple ' navigateurl= ' xxcb_add.aspx?classname= other Apple &classid=020102 '?? target= ' main1 '/>
</treenode>
<treenode text= ' peach ' navigateurl= ' xxcb_add.aspx?classname= peach &classid=0202 '?? target= ' main1 '/>
<treenode text= ' Litchi ' 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>


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.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 = "&"
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"))
K = I-j
Select Case K
Case is > 0
Txtwriter. WriteLine ("<treenode text=" "& strname &" ' Navigateurl= ' Xxcb_add.aspx?classname= "& strname &" "& St Rand & "Classid=" & Strid & "' target= ' main1 '")
Case is = 0
Txtwriter. WriteLine ("<treenode text=" "& strname &" ' Navigateurl= ' Xxcb_add.aspx?classname= "& strname &" "& St Rand & "Classid=" & Strid & "' target= ' main1 '/>")
Case is 0
Txtwriter. WriteLine ("<treenode text=" "& strname &" ' Navigateurl= ' Xxcb_add.aspx?classname= "& strname &" "& St Rand & "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 &" "& St Rand & "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 &" "& St Rand & "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 &" "& St Rand & "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 ()

This menuone.txt generates the menu source file as required.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.