The application of Menu in ASP.NET and the understanding of XmlDataSource

  • 2020-05-26 08:09:48
  • OfStack

Previously, I thought that all the menus were made by sitemap, but recently I saw that the methods in the project were determined by XmlDataSource.
Menusite. xlm file:
 
<?xmlversion="1.0"encoding="utf-8"?> 
<Menusvalue=""> 
<TopMenuid="100"value=""ImageUrl="~/App_Themes/Public/images/PublicImages/topMenu_stl.jpg"NavigateUrl=""> 
<TopMenuItemid="101"value="ApplyforShortTermLeaseofStateLand"NavigateUrl="~/TOL/Issuance/AppTOLApplication.aspx"></TopMenuItem> 
<TopMenuItemid="102"value="ManageMyExistingAccount"NavigateUrl="~/CaseEnquiry/HomeAuthenticate.aspx?ShowPanel=true"></TopMenuItem> 
<TopMenuItemid="103"value="ViewMessagesforMyApplications"NavigateUrl="~/CommonUtility/Email/ListAppCorrespondence.aspx"></TopMenuItem> 
</TopMenu> 
<TopMenuid="200"value=""ImageUrl="~/App_Themes/Public/images/PublicImages/topMenu_aosl.jpg"NavigateUrl=""> 
<TopMenuItemid="202"value="ManageMyExistingStateTitle"NavigateUrl=""></TopMenuItem> 
<TopMenuItemid="203"value="ViewMessagesforMyApplications"NavigateUrl=""></TopMenuItem> 
</TopMenu> 
<TopMenuid="300"value=""ImageUrl="~/App_Themes/Public/images/PublicImages/topMenu_lup.jpg"NavigateUrl=""> 
<TopMenuItemid="301"value="SubmitProposalforLandUse"NavigateUrl=""></TopMenuItem> 
</TopMenu> 
<TopMenuid="500"value=""ImageUrl="~/App_Themes/Public/images/PublicImages/topMenu_logout.jpg"NavigateUrl="~"Logout.aspx"> 
</TopMenu> 
</Menus> 

Create xmldatasource and asp:menu controls in html:
 
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="Menusite.xml"></asp:XmlDataSource> 
<asp:MenuDataSourceID="XmlDataSource1"runat="server"ID="Menu1"MaximumDynamicDisplayLevels="4" 
Orientation="Horizontal"StaticDisplayLevels="2"StaticEnableDefaultPopOutImage="False" 
DynamicEnableDefaultPopOutImage="false"StaticSubMenuIndent=""ItemWrap="True"> 
<DataBindings> 
<asp:MenuItemBindingDataMember="TopMenu"ImageUrlField="ImageUrl"TextField="value" 
NavigateUrlField="NavigateUrl"ValueField="value"/> 
<asp:MenuItemBindingDataMember="TopMenuItem"NavigateUrlField="NavigateUrl"TextField="value" 
ValueField="value"/> 
<asp:MenuItemBindingDataMember="Menus"TextField="value"ValueField="value"/> 
</DataBindings> 
</asp:Menu> 

menu is really comprehensive. You only need to set the properties to meet your requirements without any code:
MaximumDynamicDisplayLevels: specifies the number of dynamic display menu node layers that should be displayed after the static display layer. If set to 0, the child node will not show dynamics.
Orientation: used to set a horizontal menu bar on a page.
StaticDisplayLevels: number of layers of statically displayed menus from the root menu. The tip above is: xml must have a root node, but the menu items at layer 2 are displayed when the menu is displayed, so use this
The root node of xml, value, is set to null, then saticDisplayLeves is set to 2, so that the user sees the static display of layer 2.
StaticEnableDefaultPopOutImage: the static menu item displays by default with a small arrow, set to false, and this state will be modified.
DynamicEnableDefaultPopOutImage: sets the dynamic display to have a small arrow.
StaticSubMenuIndent: controls the depth of indenting of submenu items if these menu levels are set to display in static mode.
ItemWrap: sets whether a menu item can be wrapped.
The above Settings make it easy to create the desired menu style.

Related articles: