Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compile errors.

Posted on 2009-07-11
6
Medium Priority
?
419 Views
Last Modified: 2012-06-27
Error      2      'System.Web.SessionState.HttpSessionState' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Web.SessionState.HttpSessionState' could be found (are you missing a using directive or an assembly reference?)      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      102      29      OmegaLove

-------------------------------------------------------------------------------------
 private void RemoveLowerLevelCrumbs()
        {

            short level = 0;
            ArrayList removalList = new ArrayList(_crumbList.Count);
            foreach (var level in _crumbList.Keys)
            {
                if ((level >= _level))
                {
                    removalList.Add(level);
                }
            }
            //Now remove all keys in the list
            foreach (var level in removalList)
            {
                _crumbList.Remove(level);
            }
        }

Error      7      A local variable named 'level' cannot be declared in this scope because it would give a different meaning to 'level', which is already used in a 'parent or current' scope to denote something else      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      154      26      OmegaLove
Error      8      Operator '>=' cannot be applied to operands of type 'object' and 'short'      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      156      22      OmegaLove




                //Check our Crumb is there in the session...if not create and add it...else get it
                if (Session.Item["HASH_OF_CRUMPS"] == null)
                {
                    _crumbList = new SortedList();
                    Session.Add("HASH_OF_CRUMPS", _crumbList);
                }
                else
                {
                    _crumbList = Session.Item("HASH_OF_CRUMPS");
                }
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24833147
Error      2      'System.Web.SessionState.HttpSessionState' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Web.SessionState.HttpSessionState' could be found (are you missing a using directive or an assembly reference?)      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      102      29      OmegaLove

This is due to:
Session.Item["HASH_OF_CRUMPS"] == null and  _crumbList = Session.Item("HASH_OF_CRUMPS");
There is no Item for Session
you should get session items like this:-- Session["HASH_OF_CRUMPS"]

if (Session["HASH_OF_CRUMPS"] == null)
                {
                    _crumbList = new SortedList();
                    Session.Add("HASH_OF_CRUMPS", _crumbList);
                }
                else
                {
                    _crumbList = Session["HASH_OF_CRUMPS"];
                }
0
 

Author Comment

by:mathieu_cupryk
ID: 24833152
Error      1      Cannot implicitly convert type 'object' to 'System.Collections.SortedList'. An explicit conversion exists (are you missing a cast?)      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      135      34      OmegaLove


 protected void Page_Load(object sender, EventArgs e)
        {
            if (!(Page.IsPostBack))
            {

                //Minimum level is 1
                if ((_level <= 0))
                {
                    _level = 1;
                }

                //If no friendly name gives Untitled as default
                if ((string.IsNullOrEmpty(_tailName)))
                {
                    _tailName = "Untitled";
                }

                //Create a Crumb object based on the properties of this page
                _pageCrumb = new PageCrumb(_level, Request.RawUrl, _tailName);

                //Check our Crumb is there in the session...if not create and add it...else get it
                if (Session["HASH_OF_CRUMPS"] == null)
                {
                    _crumbList = new SortedList();
                    Session.Add("HASH_OF_CRUMPS", _crumbList);
                }
                else
                {
                    _crumbList = Session["HASH_OF_CRUMPS"];
                }

                //Now modify the List of the breadcrumb
                ModifyList();
                // Put the breadcrumb from the session of sortlist
                PutBreadCrumbs();


            }

        }

        private void ModifyList()
        {
            //Remove all Entries from the list which is higher or equal in level
            //Because at a level there can be max 1 entry in the list
            RemoveLowerLevelCrumbs();
            //If level is 1 set the Crumb as home
            if (_pageCrumb.Level == 1)
            {
                _crumbList.Clear();

                _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
            }
            else
            {
                //If nothing in the list adds the home link first
                if (_crumbList.Count == 0)
                {
                    _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
                }
                //Now add the present list also no other check is required here as we have cleaned up the
                //List at the start of the function
                _crumbList.Add(_level, _pageCrumb);
            }
        }
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24833155
Error      7      A local variable named 'level' cannot be declared in this scope because it would give a different meaning to 'level', which is already used in a 'parent or current' scope to denote something else      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      154      26      OmegaLove

This is due to declaring "level" variable to times...:
           
 1 here --->         short level = 0;
            ArrayList removalList = new ArrayList(_crumbList.Count);
 2 here--->    foreach (var level in _crumbList.Keys)
            {

So change either of the variable name eg. level1 and level2
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 41

Expert Comment

by:guru_sami
ID: 24833173
Error      8      Operator '>=' cannot be applied to operands of type 'object' and 'short'      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      156      22      OmegaLove

That is due to type mismatch :
----->  foreach (var level in _crumbList.Keys)
            {
                if ((level >= _level))
_level is short while level is object
So try like this:
foreach (short level in _crumbList.Keys)
            {
                if ((level >= _level))

0
 

Author Comment

by:mathieu_cupryk
ID: 24833178
Error      2      A local variable named 'level' cannot be declared in this scope because it would give a different meaning to 'level', which is already used in a 'parent or current' scope to denote something else      D:\inetpub\wwwroot\OmegaLove\Controls\ctrlBreadCrumb.ascx.cs      166      28      OmegaLove


using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Globalization;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.ComponentModel;

namespace OmegaLove.Web.UI
{
   
    public partial class ctrlBreadCrumb : OmegaLoveBasePageUserControl
    {
        public struct PageCrumb
        {
            private short _level;
            private string _url;
            private string _linkName;

            public PageCrumb(short level, string url, string linkName)
            {
                _level = level;
                _url = url;
                _linkName = linkName;
            }

            public short Level
            {
                get { return _level; }
            }

            public string Url
            {
                get { return _url; }
            }

            public string LinkName
            {
                get { return _linkName; }
            }
        }


        protected System.Web.UI.WebControls.Label lblTrail;
        //NOTE: The following placeholder declaration is required by the Web Form Designer.
        //Do not delete or move it.
        private System.Object designerPlaceholderDeclaration;

        //Variable holding the Link name of the page
        private string _tailName;

        //Variable holding the level of the page
        private short _level;

        //The pagecrumb object of the current page
        private PageCrumb _pageCrumb = new PageCrumb();

        //We will use a sorted list as we can use the level as key
        private SortedList _crumbList;


        //Each page has a level. The page should declare its level
        public short Level {
           // TO DO : We can check for some constraints here
           get { return _level; }
           set { _level = value; }
        }

        //Each page needs a meaningful name of it. Let them declare it
        public string TailName {
           // TO DO : We can check for some constraints here
           get { return _tailName; }
           set { _tailName = value; }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
        }

        /// <summary>
        ///            Required method for Designer support - do not modify
        ///            the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }

        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(Page.IsPostBack))
            {

                //Minimum level is 1
                if ((_level <= 0))
                {
                    _level = 1;
                }

                //If no friendly name gives Untitled as default
                if ((string.IsNullOrEmpty(_tailName)))
                {
                    _tailName = "Untitled";
                }

                //Create a Crumb object based on the properties of this page
                _pageCrumb = new PageCrumb(_level, Request.RawUrl, _tailName);

       

                //Now modify the List of the breadcrumb
                ModifyList();
                // Put the breadcrumb from the session of sortlist
                PutBreadCrumbs();


            }

        }

        private void ModifyList()
        {
            //Remove all Entries from the list which is higher or equal in level
            //Because at a level there can be max 1 entry in the list
            RemoveLowerLevelCrumbs();
            //If level is 1 set the Crumb as home
            if (_pageCrumb.Level == 1)
            {
                _crumbList.Clear();

                _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
            }
            else
            {
                //If nothing in the list adds the home link first
                if (_crumbList.Count == 0)
                {
                    _crumbList.Add((short)1, new PageCrumb(1, "/Home.aspx", "Home"));
                }
                //Now add the present list also no other check is required here as we have cleaned up the
                //List at the start of the function
                _crumbList.Add(_level, _pageCrumb);
            }
        }

        //Function will remove all the entries from the list which is higher or equal to the
        //present level
        private void RemoveLowerLevelCrumbs()
        {

            short level = 0;
            ArrayList removalList = new ArrayList(_crumbList.Count);
            foreach (short level in _crumbList.Keys)
            {
                if ((level >= _level))
                {
                    removalList.Add(level);
                }
            }
            //Now remove all keys in the list
            foreach (short level in removalList)
            {
                _crumbList.Remove(level);
            }
        }


        private void PutBreadCrumbs()
        {
            StringBuilder linkString = new StringBuilder();

            PageCrumb pageCrumb = new PageCrumb();
            int index = 0;

            for (index = 0; index <= _crumbList.Count - 2; index++)
            {
                pageCrumb = (PageCrumb)_crumbList.GetByIndex(index);
                linkString.Append(string.Format("<a href = {0} >{1} </a>", pageCrumb.Url, pageCrumb.LinkName));
                linkString.Append(" > ");
            }
            //Add the tail also
            pageCrumb = (PageCrumb)_crumbList.GetByIndex(index);
            linkString.Append(pageCrumb.LinkName);


            lblTrail.Text = linkString.ToString();
        }
    }
}
0
 

Author Comment

by:mathieu_cupryk
ID: 24833199
new question still not being solved.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question