Results 1 to 6 of 6

Thread: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Resolved [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?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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);
                }
            }
        }
    }

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)

    Hello,

    As a side note...

    For a personal stand point, putting this:

    Code:
    <&#37;# ((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

  5. #5
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)

    Quote Originally Posted by gep13 View Post
    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.

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Having trouble with Container.DataItem (CS1061 error)

    Agreed, there are some very nice features coming out in the next release!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width