1

所以我有一个我正在尝试使用升级的 asp.net 应用程序。我想要完成的是使用一个下拉列表中选择的值来确定第二个下拉列表中显示的值。为此,我创建了两个 DDL,并将它们绑定到标记中的 LINQDataSource 对象。我想我要做的是将第二个 LinqDatasource 绑定到我在表单 Load 上创建的 List(of tablename) 列表,这样我就可以将集合放在内存中并且可以在客户端运行 LINQ,因此我可以动态确定返回集数据源以及下拉列表中的值。

我看到你可以将你的 LinqDataSource 指向一个列表,只要列表是一个属性。因此,我尝试了以下操作,但收到错误消息,提示找不到我的课程。

<asp:DropDownList ID="ddlTitle" runat="server" DataTextField="Title" DataValueField="Title"
        DataSourceID="ViolationTitles" Width="203px" >
    </asp:DropDownList>

        <asp:DropDownList ID="ddlChapters" runat="server" 
        DataTextField="FullChapterName" DataValueField="Chapter_Number"
        DataSourceID="ViolationChapters" Width="203px">
    </asp:DropDownList>

    <asp:LinqDataSource ID="ViolationTitles" runat="server" 
        ContextTypeName="ARS_LINQ_Connections.ARSDataContext" EntityTypeName="" Select="new (key as Title, it as Violation_Title_Chapters)" 
        TableName="Violation_Title_Chapters" GroupBy="Title">
    </asp:LinqDataSource>

    <asp:LinqDataSource ID="ViolationChapters" runat="server"
    ContextTypeName="Test"  
        EntityTypeName="" 
        TableName="rsViolations" 
        Select='new (Title, Chapter_Number, Chapter_Name, String.Concat(Chapter_Number + ". " + Chapter_Name) as FullChapterName)'>
    </asp:LinqDataSource>

代码背后

Public Class Test
    Inherits System.Web.UI.Page
    Public Property rsViolations As New List(Of Violation_Code)

    Dim arslinq As New ARS_LINQ_Connections.ARSDataContext
    Dim rsTitles As New List(Of Violation_Title_Chapter)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        rsViolations = (From v In arslinq.Violation_Codes).ToList
        rsTitles = (From t In arslinq.Violation_Title_Chapters).ToList



    End Sub
End Class
4

0 回答 0