[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

missing a using directive or an assembly reference

Posted on 2006-06-23
16
Medium Priority
?
1,834 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-
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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