-Dman100-
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.
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.
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.
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
Which line is the compiler error on?
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);
here are the lines the errors are thrown:
BulletedList MyList = new BulletedList();
MyList.Items.Add(MyItem);
Are you using .Net 1.1 or 2.0 ?
ASKER
.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
http://aspalliance.com/247
ASKER
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.
Based on one of the workaround solutions I could bind an arraylist
<ul>
<asp:Repeater ID="TopMenu" Runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.
</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.
ASKER
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.
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.
ASKER
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>
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.
</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");
}
ArrayList is fairly simple:
public void Wibble()
{
ArrayList arr = new ArrayList();
arr.Add("Value 1");
arr.Add("Value 2");
}
ASKER
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
repeater control:
<ul>
<asp:Repeater ID="TopMenu" Runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.
</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.
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
ASKER
do I need to provide more information or is my question presented incorrectly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you carl
what would be the better approach to bind the arraylist to my repeater control?
what would be the better approach to bind the arraylist to my repeater control?