Please forgive me if I am horrible at explaining this. I have a project where I have standalone business objects. I'm trying to create an asp:listview with one of those business objects, but it keeps telling me that it's an invalid type, or not even displaying.
The business object logic is here:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using WebStore.DatabaseHelper;
using System.Configuration;
namespace WebStore.BusinessObjectHelper
{
public class ProductCategoryList
{
private BindingList<ProductCategory> _List = new BindingList<ProductCategory>();
public BindingList<ProductCategory> List
{
get { return _List; }
}
public ProductCategoryList GetAll()
{
Database db = new Database(ConfigurationManager.AppSettings["store"]);
db.Command.CommandType = System.Data.CommandType.StoredProcedure;
db.Command.CommandText = "tblProductCategory_GetAll";
DataSet ds = new DataSet();
ds = db.ExecuteQuery();
foreach (DataRow dr in ds.Tables[0].Rows)
{
ProductCategory pc = new ProductCategory();
pc.Initialize(dr);
pc.InitializeBusinessData(dr);
pc.IsNew = false;
pc.IsDirty = false;
_List.Add(pc);
}
return this;
}
public ProductCategoryList Save()
{
for (int i = 0; i < _List.Count; i++)
{
if (_List[i].IsSavable())
{
_List[i] = _List[i].Save();
}
}
return this;
}
}
}
This is what I am trying to do:
<div id="CategoryMenu" style="text-align: center">
<asp:ListView ID="categoryList" runat="server" ItemType="WebStore.BusinessObjectHelper.ProductCategoryList" SelectMethod="GetAll">
<ItemTemplate>
<b style="font-size: large; font-style: normal">
<a href="ProductList.aspx?id=<%# Eval("ID") %>">
<%# Eval("name") %>
</a>
</b>
</ItemTemplate>
<ItemSeparatorTemplate>| </ItemSeparatorTemplate>
</asp:ListView>
</div>
I get an error:
An exception of type 'System.InvalidOperationException' occurred in System.Web.dll but was not handled in user code
Additional information: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
In my code behind:
protected void Page_Load(object sender, EventArgs e)
{
categoryList.DataSource = new ProductCategoryList();
categoryList.DataBind();
}
public ProductCategoryList GetCategories()
{
var _db = new WebStore.BusinessObjectHelper.ProductCategoryList();
ProductCategoryList query = _db.GetAll();
return query;
}
Am I not able to display this object in an asp:listview?