Working with Menu Control in Asp.net
In this article we will discuss about the binding of menu control to a XML file. We will also see
the way of creating tabs in asp.net without using the ajaxtoolkit.
We will create it with the help of Menu and the multiview control available in the visualstudio tool.
First we will see creating a tab control with the help of menu and multiview control.
For this we will take a menu control and a multiview control. Multiview control will show the
content of the selected tab and menu control will display tabs.
take the controls like this:
<asp:Menu
id="menu1"
Orientation="Horizontal"
OnMenuItemClick="menu1_MenuItemClick"
Runat="server">
<Items>
<asp:MenuItem
Text="Vision"
Value="0"
Selected="true" />
<asp:MenuItem
Text="Mission"
Value="1"/>
<asp:MenuItem
Text="Values"
Value="2" />
</Items>
</asp:Menu>
<asp:MultiView
id="MVSolutions"
ActiveViewIndex="0"
Runat="server">
<asp:View ID="view1" runat="server">
To pave way for a safer and better tommorrow. Safer, by bringing blood donors and those in need to a common platform.
Better, by giving a child what he/she deserves the most, best education. In next 5 years, we aim to be the real hope of every
Indian in search of a blood donor, who believes in humanity.
</asp:View>
<asp:View ID="view2" runat="server">
To make the best use of contemporary technologies in delivering a promising web portal to bring together all the blood donors in India;
thereby fulfilling every blood request in the country.
To provide a common platform for those who have a zeal to support rural child education.
</asp:View>
<asp:View ID="view3" runat="server">
DignityExcellenceDiversityIndividual and team workCompassionAdvanceTrustIntegrityOblige
</asp:View>
</asp:MultiView>
and now in the codebehind on menu control event we will write below code:
protected void menu1_MenuItemClick(object sender, MenuEventArgs e)
{
MVSolutions.ActiveViewIndex = Int32.Parse(menu1.SelectedValue);
}
For binding the menu control with an xml file we first create an xML file.
Suppose we create it like:
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<BookType text="Technology">
<Book text="C++" author="Yashwant Kanetkar" />
<Book text="C#" author="Yashwant Kanetkar" />
</BookType>
<BookType text="Recipe">
<Book text="Vegetarian" author="Sanjeev Kapoor" />
<Book text="NonVegetarian" author="Sanjeev Kapoor" />
</BookType>
<BookType text="Children">
<Book text="Maths" author="subhash" />
<Book text="Rhymes" author="kesar" />
</BookType>
</menu>
and now we will bind this xml file with menu control with the help of xmldatasource:
<asp:Menu ID="Menu1" DataSourceID="cmlbooks" runat="server">
<DataBindings>
<asp:MenuItemBinding DataMember="BookType" TextField="text" />
<asp:MenuItemBinding DataMember="Book" TextField="text" ValueField="author" />
</DataBindings>
</asp:Menu>
<asp:XmlDataSource ID="xmlbooks" DataFile="Books.xml" runat="server" />