Horizontal Nav

Sunday, 29 June 2014

Using ASP.Net Menu control with example in C# and VB.Net


How to use ASP.Net Menu control with Menus and Submenus. The ASP.Net Menu control will be populated using Sitemap and ASP.Net SiteMapDataSource control.

This article also describes how we can selected the Menu and the Submenu or child item and change its CSS styles such has font, color, background color, etc

HTML Markup
Below is the HTML Markup of the Master Page Main.Master that contains the Menu control as well as the SiteMapDataSource control.

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
<asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
    OnMenuItemDataBound="OnMenuItemDataBound">
    <LevelMenuItemStyles>
        <asp:MenuItemStyle CssClass="main_menu" />
        <asp:MenuItemStyle CssClass="level_menu" />
    </LevelMenuItemStyles>
</asp:Menu>


Adding the Sitemap XML and understanding its use
Sitemap is nothing but a map of your site, it is an XML files which has all the Pages and the Child Pages present in the site. Whenever a new page has to be added to your site, you simply need to add its node in the sitemap XML file and the ASP.Net Menu control will automatically grab and display it.

Sitemap can be added using Add New Item Dialog of Visual Studio as shown below.


Once the file is added you need to structure it based on the Level 1 Pages and the Child Pages.
Note: You can have as many child levels as you want, here I am using 2 Level Menu structure

Below is the sitemap I am using for this article, it has the following page structure.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url=""title="Home" description="">
    <siteMapNode url="Home.aspx" title="Home" description="Home Page" />
    <siteMapNode url="javascript:;" title="Services" description="Services Page">
      <siteMapNode url ="Consulting.aspx" title="Consulting" description="Consulting Page"></siteMapNode>
      <siteMapNode url ="Outsourcing.aspx" title="Outsourcing" description="Outsourcing Page"></siteMapNode>
    </siteMapNode>
    <siteMapNode url="About.aspx" title="About" description="About Us Page" />
    <siteMapNode url="Contact.aspx" title="Contact" description="Contact Us Page" />
 </siteMapNode>
</siteMap>

Home => Home.aspx
Services
            Consulting => Consulting.aspx
            Outsourcing => Outsourcing.aspx
About => About.aspx
Contact => Contact.aspx


Styling the ASP.Net Menu Control
I have placed the following CSS style in the Head section of the Master Page. You can also make use of an external CSS class file.
In the HTML Markup section you will notice I have specified <LevelMenuItemStyles>, which consists of twoMenuItemStyle nodes. The first one is for the CSS Class of the top level or main menu and the second one is for the child or submenu

<style type="text/css">
    body
    {
        font-family: Arial;
        font-size: 10pt;
    }
    .main_menu
    {
        width: 100px;
        background-color: #8AE0F2;
        color: #000;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-right: 5px;
    }
    .level_menu
    {
        width: 110px;
        background-color: #000;
        color: #fff;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-top: 5px;
    }
    .selected
    {
        background-color: #852B91;
        color: #fff;
    }
</style>


Setting the Selected Menu at Runtime
In the HTML markup you will notice that I have specified OnMenuItemDataBound event of the ASP.Net Menu control. Here I have written the code to select the Menu so that it appears selected when rendered.

Note: When a Child or Submenu is selected then I am selecting its corresponding Parent Menu.

C#

protected void OnMenuItemDataBound(object sender, MenuEventArgs e)
{
    if (SiteMap.CurrentNode != null)
    {
        if (e.Item.Text == SiteMap.CurrentNode.Title)
        {
            if (e.Item.Parent != null)
            {
                e.Item.Parent.Selected = true;
            }
            else
            {
                e.Item.Selected = true;
            }
        }
    }
}

VB.Net

Protected Sub OnMenuItemDataBound(sender As Object, e As MenuEventArgs)
    If SiteMap.CurrentNode IsNot Nothing Then
        If e.Item.Text = SiteMap.CurrentNode.Title Then
            If e.Item.Parent IsNot Nothing Then
                e.Item.Parent.Selected = True
            Else
                e.Item.Selected = True
            End If
        End If
    End If
End Sub



Friday, 27 June 2014

Five Things to Know About Critical Path

Critical path refers to the sequence of activities that must be completed on time for the entire project to be completed on time. It is an important aspect of your project schedule. Here are five things to know about critical path.
1. Float refers to schedule flexibility
On every project, no matter how complicated, there are always some activities that can be started earlier or completed later without jeopardizing the final completion date. This flexibility between the earliest time an activity CAN be completed and the latest time when it MUST be completed is called "float".
2. The critical path has no float
Now let’s look at those activities where you do not have the flexibility in the start and end-dates. These activities cannot be completed earlier because they are pending the completion of another activity. They also cannot be completed later without causing all the succeeding activities to be late. All of these activities back up tightly against other activities that precede or succeed them. In other words, the path has zero float.
The critical path consists of the longest sequence of activities that must be started and completed exactly as scheduled. It is the longest sequence of activities with zero float.
3. Why is the Critical Path Important?
If the project is trending late it is very important to identify the critical path activities. Unless you are able to accelerate activities on the critical path, the end-date for the entire project will not change. Applying additional resources to activities that are not on the critical path will not affect the overall project end-date. Your chance to make an impact on the projected end-date relies on your ability to identify and shorten the critical path.
4. The Critical Path May Change
Given that there are many, many paths through the schedule, it’s possible for the critical path to change. For instance, say you have a project with 22 activities over nine months. Let’s assume that there is another path of work that includes 19 activities and takes 8 ½ months. There are two weeks of float on this path. Let's say one of the activities on the 8 ½ month path ends up taking an extra four weeks. Because there was only two weeks of float in the path, it will now become the critical path and force the entire project to complete in 9 1/2 months.
5. You must sequence activities to understand critical path

The critical path relies on an understanding of the successors and predecessors of each activity. If your activities are not sequenced, the critical path may be calculated erroneously. 

Four Techniques to Manage Your Schedule

You will never be a successful project manager if you do not know how to build and manage a schedule. The schedule may be the most fundamental tool for managing projects. Here are five techniques to help you take full advantage of the project schedule.  
1. The remainder of the schedule is the most important
The schedule should represent your best-guess at any particular point in time on how to complete the remaining work. The more complex your project is, the more change is going to be required in your “best guess” over time. The project manager must evaluate the schedule on an ongoing basis and determine the current state of the project. Based on the current state of the project, and your current understanding of the work remaining, you need to re-plot a course that will allow the work to be completed within the original budget and deadline.
2. Update the schedule weekly
For most projects, the schedule will need to be reviewed on a weekly basis. During this review, the project manager updates the schedule with the current state of work that is completed and in-progress. The remaining work should be evaluated to see if the project will be completed within the deadline. If it can, you are in good shape. If it cannot, the project manager must implement corrective action.
3. Proactively manage schedule variances
The project manager may be in a position of having to constantly utilize his experience and creativity to get the project completed within expectations. One week your project many be on track. The next week, you may have work assignments that are late and issues that have surfaced. If you are good at it, managing the schedule can be one of the more challenging and rewarding aspects of project management. If you do not relish the detailed work that is required, you may find it much more difficult to be successful as a project manager.
4. Validate who can update the schedule

On most projects the project manager is the only one that is allowed to update the schedule. However, there are other options, especially for larger projects. The project manager may ask each team member to update the schedule with actual hours worked, remaining hours and proposed end date. For very large projects, it is also common for one or more people to be assigned to update the schedule on behalf of the project manager. These people are sometimes called project administrators, project coordinators or project schedulers. They can get information from team members and update current status and actual hours worked. They bring this all to the project manager for final analysis and evaluation.

Tuesday, 24 June 2014

How to Create a HTML/ CSS Menu

This post will explain how to create a simple 2 level menu using HTML and CSS only. We know there are a lot of ways to create a HTML menu but at  times, we need to use only HTML/CSS in the project to create a nice menu. So, lets get started.

We will create a HTML structure as below using <ul> and <li> tags. Write the below code in your HTML file where you want to place the menu.
 <div class="menu">
     <ul>
          <li><a href="#">Menu 1</a></li>
          <li><a href="#">Menu 2</a>
          <ul>
               <li><a href="#">Menu 2.1</a></li>
               <li><a href="#">Menu 2.2</a></li>
               <li><a href="#">Menu 2.3</a></li>
          </ul>
          </li>
          <li><a href="#">Menu 3</a>
          <ul>
               <li><a href="#">Menu 3.1</a></li>
               <li><a href="#">Menu 3.2</a></li>
               <li><a href="#">Menu 3.3</a></li>
          </ul>
          </li>
     </ul>
 </div>
Now, we have the structure ready. Definitely, the current menu does not look good and we will now apply some CSS to make it look beautiful. Write the below code in the <head> section.
  <style type="text/css">
        .menu{
              width: 500px;
              margin: 0px auto;
              font-family: Arial, Helvetica, sans-serif;
              font-weight: bold;
              font-size: 14px;
              }
        .menu ul li a:link, div ul li a:visited {
              display: block;
              background-color: #f1f1f1;color:#000;
              text-align: center;
              text-decoration: none;
              padding: 4px;
              border-bottom: 1px solid #fff;
              width: 150px;
              }
         .menu ul li a:hover{
              background-color: #ccc;
              }
         .menu ul li ul li a:link, li ul li a:visited {
              display: block;
              background-color: #f1f1f1;
              color: #000;
              text-align: center;
              text-decoration: none;
              padding: 4px;
              border-bottom: 1px solid #fff;
              width: 150px;
              }
         .menu ul li ul li a:hover {
              background-color: #ccc;
              }
         .menu ul {
              list-style-type: none;
              margin: 0px;
              padding: 0px;
              }
         .menu ul li {
              float: left;
              margin-left: 5px;
              }
         .menu ul li ul li {
              float: none;
              margin-left: 0px;
              }
         .menu ul li ul {
              display: none;
              }
         .menu li:hover ul{
              display: block;
              }
  </style>

Save the HTML file and double click on it to view on the browser. Your menu should look something like the below screesnhot.