What is the best way to populate a menu control on the main page?

Database? Variable Pages? Enum?

I am looking for opinions here.

+3
source share
8 answers

The ASP.NET Sitemap function is built for this and works well in many cases. If you get to the place where you want your Menu to look different than your Sitemap, here are some workarounds .

, Sitemap. , , , , , , , .

+4

, .

XML, , ASP.NET/ "sitemap". , , , Visual Studio .

, , , , .

+2

, ASP.NET / - ASP.NET. .

ASPView TreeView Menu, SiteMapDataSource. , .

  • web.sitemap. - ASP.NET .

  • .master & hellip;

    <asp:SiteMapPath ID="SiteMapPath1" runat="server" />
    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource2" />
    <asp:TreeView ID="TreeView1" runat="server"  DataSourceID="SiteMapDataSource1" />
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    <asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="False" />
    
  • securityTrimmingEnabled "true" web.config & hellip;

    <?xml version="1.0"?>
    <configuration>
        ...
        <system.web>
            ...
            <siteMap defaultProvider="default">
                <providers>
                    <clear/>
                    <add name="default"
                        type="System.Web.XmlSiteMapProvider"
                        siteMapFile="web.sitemap"
                        securityTrimmingEnabled="true"/>
                </providers>
            </siteMap>
            ...
        </system.web>
        ...
    </configuration>
    
  • master.vb & hellip;

    Protected Sub TreeView1_DataBound( ByVal sender As Object, ByVal e As EventArgs ) Handles TreeView1.DataBound
    
        'Collapse unnecessary menu items...
        If TreeView1.SelectedNode IsNot Nothing Then
            Dim n As TreeNode = TreeView1.SelectedNode
            TreeView1.CollapseAll()
            n.Expand()
            Do Until n.Parent Is Nothing
                n = n.Parent
                n.Expand()
            Loop
        Else
            TreeView1.ExpandAll()
        End If
    
    End Sub
    
+1

, . , , , .

, ,

0

Sitemap, , .

0

, . , . , CMS, . , , . " " , .

0

.

, .

, . UIP ComponentArt - .

BTW ComponentArt . , , .

0

Effective access is a core feature from a user's perspective. A general suggestive approach is dictionary search , which is well suited for large and nested menu structures. The user moves on clicks or unique keystrokes, optionally an up arrow (right) or back arrow (left) up / down, as usual. I would suggest filling the menu on demand other than the original, and providing a javascript action when the last item is selected.

0
source

Source: https://habr.com/ru/post/1696776/


All Articles