Practical-15
Problem Statement
Write a program using Menu Control.
Solution
To create a program using Menu Control in ASP.NET, follow the steps below:
- Create a new ASP.NET Web Application project in Visual Studio.
- Add a new Web Form to the project by right-clicking on the project in the Solution Explorer, selecting "Add" > "Web Form".
- Rename the Web Form to "Default.aspx".
- Open the "Default.aspx" file and design the user interface as per your requirements using HTML and ASP.NET controls.
- Add the following controls to the "Default.aspx" form:
- Menu control:
<asp:Menu ID="menuControl" runat="server" Orientation="Horizontal"></asp:Menu>
- Menu control:
- In the code-behind file, write the following code in the Page_Load event handler to populate the Menu control:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MenuItem homeItem = new MenuItem("Home");
MenuItem aboutItem = new MenuItem("About");
MenuItem contactItem = new MenuItem("Contact");
menuControl.Items.Add(homeItem);
menuControl.Items.Add(aboutItem);
menuControl.Items.Add(contactItem);
}
}
- Build and run the application to see the Menu control in action.
This completes the solution for creating a program using Menu Control in ASP.NET.