gridview没有通过BLL显示值?

时间:2012-07-08 13:16:29

标签: c# asp.net gridview business-logic-layer

我的控件不会返回gridview中的值。

表适配器运行查询并显示数据。

以下是我在控件中的代码:

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

这是我的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;
        }


    }

}

我的DAL看起来像这样:

enter image description here

如果直接连接到DAL,我可以显示值。所以我认为我的BLL有问题,但它可能是什么?我没有收到任何错误消息。

我的gridview来源:

    <asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle" AutoGenerateColumns="True">
       <HeaderStyle CssClass="HeaderStyle" />
       <AlternatingRowStyle CssClass="AlternatingRowStyle" />
    </asp:GridView>

3 个答案:

答案 0 :(得分:1)

您是否定义了任何列?或者是AutoGenerateColumns == true

答案 1 :(得分:1)

  1. categoriesBLL categoriesLogic = new categoriesBLL();

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

  3. GridView1.DataBind();

  4. 将第2行更改为以下

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

答案 2 :(得分:0)

我通过分配数据表来解决这个问题:

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

    }

}