Tuesday, January 13, 2015

Working with ASP.NET Menu Controls

Today I share with you video tutorial on how to work with Menu Control of ASP.NET



Menu control of ASP.NET is collection of objects of type MenuItem.

It is navigation control that lets you create infinite number of levels with Menu->Sub Menu --> Sub Sub Menu and so on..

It has many formatting options. You can choose from built in styles or make your own style by setting various styles properties available with menu control.

In this video we are first going to create a menu design time and then at run time.

By run time I mean we will populate menu control at run time. Menu control will be present on form at design time but it will not have any object of type MenuItems. However since it will not be populated initially we will only see menu control once it becomes populated.

Selecting auto-format option give you list of pre-defined styles to format your menu.

You can add items in menu manually or automatically by selecting "Edit" items Editor" .

You can also bind your menu control with a data source (Usuallly an XML file) or sitemap or database table.

You can do this by selecting Choose Data Source --> New Data Source.

YOu can add item in menu by design time by clicking "Edit Menu Items" option from menu or select "Items" property from property window.

It will get you "Menu Item Editor" dialogue box. Using this window you can add items to menu and set various properties for menu items, individually.

Navigation URL property specifies a navigation path that is followed if particular menu item is selected

Procedure to add new items to menu is similar to adding new items to Listbox or DropdownList controls.

Here instead of making objects of type ListItems we make object of type MenuItems.

And then we can add object to Menu using Add() method.

Like we are setting Text property of MenuItem, you can set NavigationUrl property in same way.

Now, we want to add child to our menu.

We want to check if user has selected any item from menu or not, if user has selected any item from menu, new item that is added to menu is added as child of selected items otherwise, it is added as root.

For this we will write if condition to check if what item user has selected


Please share, subscribe and like.

No comments:

Post a Comment

IndiBlogger - The Indian Blogger Community