Solved

missing a using directive or an assembly reference

Posted on 2006-06-23
16
1,821 Views
Last Modified: 2008-01-09
I'm a newbie to .net and C#...just starting to learn my way around.

I'm trying to create a simple user control with a custom unordered list.

namespace compass.user_controls
{
      using System;
      using System.Data;
      using System.Drawing;
      using System.Web;
      using System.Web.UI.WebControls;
      using System.Web.UI.HtmlControls;

      /// <summary>
      ///            Summary description for TopNavBar.
      /// </summary>
      public class TopNavBar : System.Web.UI.UserControl
      {
            protected System.Web.UI.WebControls.ListBox ListBox1;

            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  BulletedList MyList = new BulletedList();
                  //MyList.BulletStyle = BulletStyle.Numbered;
                  ListItem MyItem = new ListItem();
                  MyItem.Text = "About Us";"Contact Us";"Customer Support";"Site Map";
                  MyList.Items.Add(MyItem);
                  form1.Controls.Add(MyList);
            }

What is the directive I need to add?

Thanks.
0
Comment
Question by:-Dman100-
16 Comments
 
LVL 12

Expert Comment

by:gbzhhu
ID: 16970667
Are you referencing System.web and system.data.  Check your project explorer, expand the references, see if they are in there.  If they are not add the refrences
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16970694
Which line is the compiler error on?
0
 

Author Comment

by:-Dman100-
ID: 16971009
both system.web and system.data are refereced.

here are the lines the errors are thrown:

BulletedList MyList = new BulletedList();

MyList.Items.Add(MyItem);
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16971100
Are you using .Net 1.1 or 2.0 ?
0
 

Author Comment

by:-Dman100-
ID: 16971115
.Net 1.1 Framework
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16971226
Then thats your problem, the BulletedList control was introduced in 2.0.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16971235
There are some suggested workarounds for creating a BulletedList with 1.1 here:

    http://aspalliance.com/247
0
 

Author Comment

by:-Dman100-
ID: 16971483
Is an arraylist available in .Net 1.1?

Based on one of the workaround solutions I could bind an arraylist

<ul>
<asp:Repeater ID="TopMenu" Runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "MenuItems") %>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>

ArrayList MenuItems = New ArrayList()

I'm still getting errors and not making much headway with this.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16971553
Yup, ArrayList is under the System.Collections namespace.
0
 

Author Comment

by:-Dman100-
ID: 16971625
is there a good article or tutorial on creating an arraylist using C#?

I've added the System.Collections namespace

But, I'm still having trouble creating the arraylist, which is just a symptom of not know what I'm doing.

Thanks for your help.
0
 

Author Comment

by:-Dman100-
ID: 16971743
well, I made some headway:

namespace compass.user_controls
{
      using System;
      using System.Collections;
      using System.Data;
      using System.Drawing;
      using System.Web;
      using System.Web.UI.WebControls;
      using System.Web.UI.HtmlControls;

      /// <summary>
      ///            Summary description for TopNavBar.
      /// </summary>
      public class TopNavBar : System.Web.UI.UserControl
      {
            public ArrayList MenuItems = new ArrayList();

      private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  
                  ArrayList MenuItems = new ArrayList();
                  MenuItems.Add("About Us");
                  MenuItems.Add("Contact Us");
                  MenuItems.Add("Customer Support");
                  MenuItems.Add("Site Map");
            }

I'm not getting any errors, but where am I going wrong on binding my arraylist?

<ul>
<asp:Repeater ID="TopMenu" Runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "MenuItems") %>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16971752
What exactly are you having trouble with ?

ArrayList is fairly simple:

    public void Wibble()
    {
        ArrayList arr = new ArrayList();
        arr.Add("Value 1");
        arr.Add("Value 2");
    }
0
 

Author Comment

by:-Dman100-
ID: 16971861
I almost have it working.  This is what I've got:

repeater control:

<ul>
<asp:Repeater ID="TopMenu" Runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "MenuItems") %>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>

code-behind:

namespace compass.user_controls
{
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
///            Summary description for TopNavBar.
/// </summary>
public class TopNavBar : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Repeater TopMenu;
public ArrayList MenuItems = new ArrayList();

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
                  
ArrayList MenuItems = new ArrayList();
MenuItems.Add("About Us");
MenuItems.Add("Contact Us");
MenuItems.Add("Customer Support");
MenuItems.Add("Site Map");
                  
TopMenu.DataSource = MenuItems;
TopMenu.DataBind();
}

compiler error message:

DataBinder.Eval: 'System String' does not contain a property with the name MenuItems
0
 

Author Comment

by:-Dman100-
ID: 16972747
do I need to provide more information or is my question presented incorrectly?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 16972824
Binding usually has to be done to a property rather than just a public member. You'll also need to change the name of your ArrayList in order to avoid a name clash:

So change:

    public ArrayList MenuItems = new ArrayList();

To:

    private ArrayList _MenuItems = new ArrayList();

And add:

    public ArrayList MenuItems
    {
         get { return _MenuItems; }
         
         // only add this next line if the compiler complains
         set { _MenuItems = value; }
    }

You'll also need to change any other reference to MenuItems in your code to _MenuItems.
0
 

Author Comment

by:-Dman100-
ID: 16972869
thank you carl

what would be the better approach to bind the arraylist to my repeater control?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now