I have a class defined in a namespace:
namespace Artworking
{
public class Category
{
int ID {get;set;}
string Name {get;set;}
public Category(int ID, string Name)
{
this.ID = ID;
this.Name = Name;
}
public Category(int ID)
{
using (CrystalCommon.MainContext db = new CrystalCommon.MainContext())
{
var q = (from c in db.tblArtworkTemplateCategories where c.ID == ID select c).SingleOrDefault();
this.ID = q.ID;
this.Name = q.CatName;
}
}
}
}
On my content page I fetch all the Categories from another function and add them a listbox control:
// Category select
Artworking.Category[] Cats = Artworking.CommonFunctions.FetchAllCategories(Master.LoggedInUser.Client.ID);
foreach(Artworking.Category C in Cats){
ListItem NewItem = new ListItem();
NewItem.Text = C.Name;
NewItem.Value = C.ID;
CategorySelect.Items.Add(NewItem);
}
However for some reason on the NewItem.Text = C.Name line it throws:
CS1061: ‘Artworking.Category’ does not
contain a definition for ‘Name’ and no
extension method ‘Name’ accepting a
first argument of type
I’m a bit confused about this one, I thought it’s all defined properly?
‘Artworking.Category’ could be found
(are you missing a using directive or
an assembly reference?)
You still need to add
publicbefore your property declarations inside theCategoryclass.