Link to home
Start Free TrialLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

missing a using directive or an assembly reference

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.
Avatar of gbzhhu
gbzhhu
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of dstanley9
dstanley9

Which line is the compiler error on?
Avatar of -Dman100-

ASKER

both system.web and system.data are refereced.

here are the lines the errors are thrown:

BulletedList MyList = new BulletedList();

MyList.Items.Add(MyItem);
Avatar of Carl Tawn
Are you using .Net 1.1 or 2.0 ?
.Net 1.1 Framework
Then thats your problem, the BulletedList control was introduced in 2.0.
There are some suggested workarounds for creating a BulletedList with 1.1 here:

    http://aspalliance.com/247
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.
Yup, ArrayList is under the System.Collections namespace.
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.
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>
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");
    }
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
do I need to provide more information or is my question presented incorrectly?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you carl

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