在asp.net listview中显示一个到多个linqdatasource联接表记录

本文关键字:linqdatasource 记录 一个 listview net 显示 asp | 更新日期: 2023-09-27 17:52:41

我对asp.net数据绑定没有很好的了解,根本无法找到或弄清楚如何在列表视图中对子表记录进行数据绑定。我已经能够链接数据库中的表键,并且这种关系是由linqdatasource创建向导检测到的。下面的代码是我得到的最远/最接近的代码,它是a"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实体记录时,这似乎过多了。关于在数据绑定上下文中使用这些实体有什么想法或指针吗?

在asp.net listview中显示一个到多个linqdatasource联接表记录

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