【问题标题】:DNN 7 Nested Repeater with LINQ带有 LINQ 的 DNN 7 嵌套中继器
【发布时间】:2014-08-18 16:21:02
【问题描述】:

我在下面的链接中使用了这个答案作为示例。但我无法让 Imports 语句在 ASCX 文件中工作。有没有办法在内部转发器中显示数据,所以我不必导入该命名空间? ascx 文件中的命名空间出错 - “错误 CS0246:找不到类型或命名空间名称“数据”(您是否缺少 using 指令或程序集引用?)---> System.Web.HttpCompileException:“

Databind repeater using Linq with group by

ASCX

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="Christoc.Modules.ProductFilter.View" %>
<%@ Import  Namespace="System.Data" %>
<asp:Repeater ID="rptCategories" runat="server" OnItemDataBound="rptCategories_ItemDataBound">
<ItemTemplate>
    <div>
        Category: <b><%# Container.DataItem%></b>
        <asp:Repeater ID="rptOptions" runat="server">
            <FooterTemplate>
                <%="</ul>" %>
            </FooterTemplate>
            <HeaderTemplate>
                <%= "<ul>"%>
            </HeaderTemplate>
            <ItemTemplate>
                <li>
                    <%# ((Data.DataRow)Container.DataItem)[1] %>, <%#  ((Data.DataRow)Container.DataItem)[0] %>
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </div>                
</ItemTemplate>

代码背后

var cc = new CategoryMappingsController();
            var listview = cc.ListCategories(ModuleId);
            catOptData = listview.ConvertToDataTable(record => new object[] { listview });
            rptCategories.DataSource = (from x in catOptData.AsEnumerable() select x["CategoryName"]).Distinct(); ;
            rptCategories.DataBind();

绑定函数

protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptr = (Repeater)e.Item.FindControl("rptOptions");
            rptr.DataSource = catOptData.AsEnumerable();//.Where(x => x["CategoryName"].Equals(e.Item.DataItem));
            rptr.DataBind();

            Repeater NestedRepeater = (Repeater)e.Item.FindControl("NestedRepeater");
            NestedRepeater.DataSource = e.Item.DataItem;
            NestedRepeater.DataBind();
        }
    }

【问题讨论】:

    标签: c# linq dotnetnuke


    【解决方案1】:

    您正在导入System.Data,但在代码中使用Data.xxx。没有帮助,编译器无法找到 Data 命名空间。要么从导入中删除.Data,要么从代码中删除Data.。我建议后者。

    <%@ Import  Namespace="System.Data" %>
    

    或者:

    <%# ((DataRow)Container.DataItem)[1] %>, <%#  ((DataRow)Container.DataItem)[0] %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多