c# tutorials and examples code for web developers

How to use Menu control in

Menu web server control

Menu control is a Navigation Toolbox Control. Here i show a simple example of Menu control.

First you need to create a Web.sitemap file. Here is the source code of Web.sitemap file. This is the main file where we store all navigation url.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="" >
  <siteMapNode url="Default.aspx" title="Home"  description="Home Page">
    <siteMapNode url="StandardToolBox.aspx" title="Standard ToolBox Control"  description="Standard ToolBox Control">
      <siteMapNode url="BulletedList.aspx" title="BulltedList Example"  description="BulltedList Control Simple Example" />
      <siteMapNode url="CheckBox.aspx" title="CheckBox Example"  description="CheckBox Control Simple Example" />
      <siteMapNode url="CheckBoxList.aspx" title="CheckBoxList Example"  description="CheckBoxList Control Simple Example" />
    <siteMapNode url="DataToolBox.aspx" title="Data ToolBox Control"  description="Data ToolBox Control">
      <siteMapNode url="SqlDataSource.aspx" title="SqlDataSource Example"  description="SqlDataSource Simple Example" />
      <siteMapNode url="XmlDataSource.aspx" title="XmlDataSource Example"  description="XmlDataSource Simple Example" />
Place the Menu Control
Now create a WebForm name Default.aspx. Then place a SiteMapDataSource Control and a Menu Control. This is very simple file. Here is the source code of Default.aspx.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">


<html xmlns="">
<head runat="server">
    <title>Menu Control Simple Example</title>
    <form id="form1" runat="server">
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"></asp:Menu>

Run the Default.aspx file. When you click a link then it goes the specific page.

Related examples