-1

My control doesnt return the values in my gridview.

table adapter runs the query fine and displays the data.

Here is my code from the control:

 categoriesBLL categoriesLogic = new categoriesBLL();
 GridView1.DataSource = categoriesLogic.GetCategories();
 GridView1.DataBind();

and here is my BLL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NopSolutions.NopCommerce.Nop.DataAccess.MegaProductMenuTableAdapters;

namespace NopSolutions.NopCommerce.BusinessLogic.MegaProductsMenu
{
    [System.ComponentModel.DataObject]
    public class categoriesBLL
    {

        private Nop_CategoryTableAdapter _categoriesAdapter = null;
        protected Nop_CategoryTableAdapter Adapter
        {
            get
            {
                if (_categoriesAdapter == null)
                    _categoriesAdapter = new Nop_CategoryTableAdapter();

                return _categoriesAdapter;
            }
        }



        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public Nop_CategoryTableAdapter GetCategories()
        {
            return _categoriesAdapter;
        }


    }

}

My DAL looks like this:

enter image description here

If connect directly to the DAL I can get the values to show up. So i think there is something wrong with my BLL, but what could it be? I receive no error messages.

My gridview source:

    <asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle" AutoGenerateColumns="True">
       <HeaderStyle CssClass="HeaderStyle" />
       <AlternatingRowStyle CssClass="AlternatingRowStyle" />
    </asp:GridView>
SOLDIER-OF-FORTUNE
  • 1,634
  • 5
  • 39
  • 66

3 Answers3

1

Do you have any columns defined? or is AutoGenerateColumns == true

Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
1
  1. categoriesBLL categoriesLogic = new categoriesBLL();

  2. GridView1.DataSource = categoriesLogic.GetCategories();

  3. GridView1.DataBind();

Change the line 2 to the following

GridView1.DataSource = categoriesLogic.Adapter.GetCategories();
  • this doesn't solve it. I get: **'NopSolutions.NopCommerce.BusinessLogic.MegaProductsMenu.categoriesBLL.Adapter' is inaccessible due to its protection level** – SOLDIER-OF-FORTUNE Jul 08 '12 at 13:46
  • then when i change `private Nop_CategoryTableAdapter _categoriesAdapter = null;` to public and do what you said, i still get no values showing. – SOLDIER-OF-FORTUNE Jul 08 '12 at 13:47
  • Please check weather calling Fill() instead of GetCategories() works or not? And set the AutoGenerateColumns to true. – Ehsan Aleem Avee Jul 08 '12 at 13:52
  • It doesnt allow me to do fill – SOLDIER-OF-FORTUNE Jul 08 '12 at 13:56
  • OR you can do the following [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)] public Nop_Category GetCategories() { return Adapter.GetCategories(); } – Ehsan Aleem Avee Jul 08 '12 at 13:59
  • **Cannot implicitly convert type 'NopSolutions.NopCommerce.Nop.DataAccess.MegaProductMenu.Nop_CategoryDataTable' to 'NopSolutions.NopCommerce.Nop.DataAccess.MegaProductMenuTableAdapters.Nop_CategoryTableAdapter'** – SOLDIER-OF-FORTUNE Jul 08 '12 at 14:02
0

I solved this by asigning the datatable:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NopSolutions.NopCommerce.Nop.DataAccess.MegaProductMenuTableAdapters;

namespace NopSolutions.NopCommerce.BusinessLogic.MegaProductsMenu
{
    [System.ComponentModel.DataObject]
    public class categoriesBLL
    {

        private Nop_CategoryTableAdapter _categoriesAdapter = null;
        protected Nop_CategoryTableAdapter Adapter
        {
            get
            {
                if (_categoriesAdapter == null)
                    _categoriesAdapter = new Nop_CategoryTableAdapter();

                return _categoriesAdapter;
            }
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public NopCommerce.Nop.DataAccess.MegaProductMenu.Nop_CategoryDataTable GetCategories()
        {
            return Adapter.GetCategories();
        }

    }

}
SOLDIER-OF-FORTUNE
  • 1,634
  • 5
  • 39
  • 66