首页 > 解决方案 > 为什么asp.net显示表名而不是表字段

问题描述

我正在做一个项目,我正在组合 3 个表,这些表已经在 dbml 中关联,但我的问题是,当我使用数据列表时,它会显示我的表名而不是正确的字段,这是大学作业,但我已经尝试了我所知道的一切做。

我试图在 sql 管理器中将它们单独组合在 vs 但我只是不明白为什么它没有显示正确的东西

 <form id="form1" runat="server">
        <div>
            <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="assign_6_final.DataClasses1DataContext" EntityTypeName="" Select="new (CustomerID, Name)" TableName="Customers">
            </asp:LinqDataSource>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="CustomerID" OnSelectedIndexChanged="Page_Load">
            </asp:DropDownList>
            <asp:DataList ID="DataList1" runat="server" DataSourceID="LinqDataSource2" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnDataBinding="DataList1_SelectedIndexChanged">
                <ItemTemplate>
                    IncidentID:
                    <asp:Label ID="IncidentIDLabel" runat="server" Text='<%# Eval("IncidentID") %>' />
                    <br />
                    DateOpened:
                    <asp:Label ID="DateOpenedLabel" runat="server" Text='<%# Eval("DateOpened") %>' />
                    <br />
                    DateClosed:
                    <asp:Label ID="DateClosedLabel" runat="server" Text='<%# Eval("DateClosed") %>' />
                    <br />
                    Title:
                    <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
                    <br />
                    Description:
                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                    <br />
                    CustomerID:
                    <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
                    <br />
                    Technician:
                    <asp:Label ID="TechnicianLabel" runat="server" Text='<%# Eval("Technician") %>' />
                    <br />
                    Product:
                    <asp:Label ID="ProductLabel" runat="server" Text='<%#  Eval("Product") %>' />
                    <br />
                    <br />
                    <br />
                </ItemTemplate>
            </asp:DataList>
        </div>
        <asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="assign_6_final.DataClasses1DataContext" EntityTypeName="" Select="new (IncidentID, DateOpened, DateClosed, Title, Description, CustomerID, Technician, Product)"  TableName="Incidents" Where="CustomerID = @CustomerID">
            <WhereParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="CustomerID" PropertyName="SelectedValue" Type="Int32" />
            </WhereParameters>
        </asp:LinqDataSource>


        <asp:EntityDataSource ID="EntityDataSource1" runat="server">
        </asp:EntityDataSource>


    </form>
</body>

我期望的结果是产品和技术人员可以正确输出最后 2 个项目,但他们没有,我有点迷失了我的老师说这是 asp 中的一个常见问题,但我从未见过

标签: c#asp.netlinq-to-sql

解决方案


尝试使用以下等:

 <%# DataBinder.Eval(Container.DataItem,"CustomerID") %>

推荐阅读