【问题标题】:display one to many linqdatasource joined table records in asp.net listview在 asp.net listview 中显示一对多 linqdatasource 连接的表记录
【发布时间】:2014-03-24 18:26:20
【问题描述】:

我完全不了解asp.net 数据绑定,无法找到或弄清楚如何在列表视图中对子表记录进行数据绑定。我已经能够链接数据库中的表键,并且通过 linqdatasource 创建向导检测到该关系。下面的代码与我所得到的一样远/近,它牦牛 “DataBinding:‘DynamicClass1’不包含名为‘prtitem’的属性。”请求页面时出错。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="RecentMnBlg.aspx.cs" Inherits="rwhifonline.Prodtctvty.RecentMnBlg" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:LinqDataSource ID="LinqDataSourceNotesAndTags" runat="server" ContextTypeName="sitedbDataContext" EntityTypeName="" Select="new (PKID, NoteText, NoteTags)" TableName="Notes" OrderBy="PKID desc"></asp:LinqDataSource>
    <h3>notes</h3>
    <asp:ListView ID="ListViewNotes" runat="server" DataSourceID="LinqDataSourceNotesAndTags">
        <ItemTemplate>
            <div class="item">
                <br />
                <asp:Label ID="NoteTextLabel" runat="server" Text='<%# Eval("NoteText") %>' />
                <br />
                PRTags:
                <!--<asp:Label ID="PRTagsLabel" runat="server" Text='<%# Eval("PRTags") %>' /> -->
                <% var prtags = (IEnumerable)Eval("PRTags");
                    foreach (object prtitem in prtags) { %> 
                    <asp:Label ID="PRTagsLabel" runat="server" Text='<%# Eval("prtitem.TagText") %>' />       
                <% } %>
                <br />
            </div>
        </ItemTemplate>
        <LayoutTemplate>
            <div id="itemPlaceholderContainer" runat="server">
                <span runat="server" id="itemPlaceholder" />
            </div>
        </LayoutTemplate>
    </asp:ListView>
</asp:Content>

注释位显示: 标签中的“System.Data.Linq.EntitySet`1[NoteTag]” 当页面在没有任何 foreach 尝试部分的情况下呈现时。

我在搜索中看到了一些关于使用数据绑定事件的页面,该事件从返回数据项列表的单独页面调用中获取列表,但是当那里有 linq 实体记录时,这似乎过多。 关于在数据绑定上下文中使用这些实体的任何想法或指示?

【问题讨论】:

    标签: c# asp.net linq data-binding


    【解决方案1】:

    能够使用 IList 参数调用页面代码后面的方法,并从每个 linq-ed 记录返回所需的字符串格式列表

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 2023-03-09
      相关资源
      最近更新 更多