[RESOLVED] Having trouble with Container.DataItem (CS1061 error)
I have this code in my .aspx page:
Code:
<asp:TemplateField HeaderText="Products">
<ItemTemplate>
<asp:BulletedList ID="BulletedList1" runat="server" DataSource='<%# ((Northwind.SuppliersRow)((System.Data.DataRowView)e.Row.DataItem).Row).GetProducts() %>'
DataTextField="ProductName">
</asp:BulletedList>
</ItemTemplate>
</asp:TemplateField>
But when I run it, i get this CS1061 error: 'Northwind.SuppliersRow' does not contain a definition for 'GetProducts' and no extension method 'GetProducts' accepting a first argument of type 'Northwind.SuppliersRow' could be found (are you missing a using directive or an assembly reference?)'
Weird thing is, I have this code in the code-behind, which works and compiles fine:
Code:
protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Northwind.SuppliersRow)((System.Data.DataRowView)e.Row.DataItem).Row).GetProducts();
}
}
Any ideas?
Re: Having trouble with Container.DataItem (CS1061 error)
by the way, I added a class file containing this code to extend the SuppliersRow class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NorthWindDatabaseApp.App_Code
{
public partial class Northwind
{
public partial class SuppliersRow
{
public Northwind.ProductsDataTable GetProducts()
{
NorthwindTableAdapters.ProductsTableAdapter adapter = new NorthWindDatabaseApp.App_Code.NorthwindTableAdapters.ProductsTableAdapter();
return adapter.GetProductsBySupplierId(this.SupplierID);
}
}
}
}
Re: Having trouble with Container.DataItem (CS1061 error)
figured it out. It's because my project is a "Web Application", and if the typed dataset is placed in the App_Code folder, it won't work. However, if the project was a "Web Site", then the dataset would work even if it's inside the App_Code folder.
Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)
Hello,
As a side note...
For a personal stand point, putting this:
Code:
<%# ((Northwind.SuppliersRow)((System.Data.DataRowView)e.Row.DataItem).Row).GetProducts() %>
Into your ASPX markup is not a good idea. It would be much better for you to do this in the Code Behind, as you did in your second code block.
Gary
Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)
Quote:
Originally Posted by
gep13
Hello,
As a side note...
For a personal stand point, putting this:
Code:
<%# ((Northwind.SuppliersRow)((System.Data.DataRowView)e.Row.DataItem).Row).GetProducts() %>
Into your ASPX markup is not a good idea. It would be much better for you to do this in the Code Behind, as you did in your second code block.
Gary
Can't wait for vNext to come out.
After using the MVVM pattern in Silverlight for the past couple of years it pains me to put anything but UI logic in the code behind.
Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)
Agreed, there are some very nice features coming out in the next release!
Gary