?
Solved

missing a using directive or an assembly reference

Posted on 2006-06-23
16
Medium Priority
?
1,833 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

766 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