Solved

missing a using directive or an assembly reference

Posted on 2006-06-23
16
1,824 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 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