0

シナリオは次のとおりです。テーブルtransactionsとからデータをクエリすることから始めましたv_patients。そのクエリをに実行しますList(Of transaction)。最終的なプロジェクションとGroupMatchListViewに到達するまで、そのリストを操作(Concat()、、など)します。マークアップにコマンドを持つLinkBut​​tonがいくつかあります。次に、リストを並べ替えるイベントハンドラーに何かを書き込む必要があります。IComparerを使用するか、何らかの方法でListViewを並べ替える必要があると思いますが、困惑しています。別のSQLクエリを実行して、リストの操作をやり直したくありません。助けてくれてありがとう!GroupBy()DataBind()SortGroupMatchListView_SortingGroupMatchListView.Items.OrderBy

最終的な予測:

Dim goliath = From f In wholeResults _
                          Group f By f.v_patient Into Group _
                          Order By v_patient.last_name, v_patient.first_name, v_patient.date_of_birth _
                          Select New With {.PatientID = v_patient.patient_id, .LastName = v_patient.last_name, .FirstName = v_patient.first_name, _
                             .DOB = v_patient.date_of_birth, .Ins = v_patient.insname, .MatchCount = Group.Count(), .Matches = Group}

            GroupMatchListView.DataSource = goliath
            GroupMatchListView.DataBind()

並べ替えコマンドのあるボタンがいくつかあります。

<th id="Th4" runat="server" style="width: 100px" width="100px">
                                        <asp:LinkButton ID="SortLastNameButton" runat="server" CommandName="Sort" CommandArgument="LastName" ForeColor="White">Last Name</asp:LinkButton>
                                    </th>
                                    <th id="Th5" runat="server" style="width: 100px" width="100px">
                                        <asp:LinkButton ID="SortFirstNameButton" runat="server" CommandName="Sort" CommandArgument="FirstName" ForeColor="White">First Name</asp:LinkButton>
                                    </th>
                                    <th id="Th6" runat="server" style="width: 85px" align="center" width="85px">
                                        <asp:LinkButton ID="SortDOBButton" runat="server" CommandName="Sort" CommandArgument="DOB" ForeColor="White" ToolTip="Date of Birth">DOB</asp:LinkButton>
                                    </th>
                                    <th id="Th7" runat="server" style="width: 185px" width="185px">
                                        <asp:LinkButton ID="SortInsuranceButton" runat="server" CommandName="Sort" CommandArgument="Ins" ForeColor="White">Insurance</asp:LinkButton>
                                    </th>

ソートロジックを配置した場所:

 Protected Sub GroupMatchListView_Sorting(sender As Object, e As System.Web.UI.WebControls.ListViewSortEventArgs) Handles GroupMatchListView.Sorting
        ''
        ''Something goes here that sorts the ListView
        ''Maybe something that uses
        ''IComparer
        ''or
        ''GroupMatchListView.Items.OrderBy()
    End Sub

再度、感謝します。

編集:私は正しい方向に進んでいると思います。GroupMatchListView.Itemsを取得し、OrderByを使用して、結果をList(Of ListViewDatItems)に割り当てます。次に、GroupMatchListView.Itemsをクリアし、ListViewDataItemsのリストからアイテムを追加し直します。しかし、ページに戻っても何も変わっていません。DataBind()だけを使用すると、空のListViewが表示されます。ListViewDataItemsのリストをDataSource、次にDataBindとして割り当てると、エラーが発生します。誰かが私がこれをまとめることができる方法を知っていますか?

これが私が解決したことです:

    Protected Sub GroupMatchListView_Sorting(sender As Object, e As System.Web.UI.WebControls.ListViewSortEventArgs) Handles GroupMatchListView.Sorting

            Dim caesar As List(Of ListViewDataItem) = (GroupMatchListView.Items.OrderBy(Function(i) CType(i.FindControl("FirstName"), Label).Text)).ToList()

            GroupMatchListView.Items.Clear()

            For Each i As ListViewDataItem In caesar
                GroupMatchListView.Items.Add(i)
            Next

            ''I don't know what comes next.  The following does not work:
            ''GroupMatchListView.DataSource = GroupMatchListView.Items
            ''GroupMatchListView.DataBind()
        End Sub
4

1 に答える 1

0

ええと、GroupMatchesListView.Itemsではできませんでした。代わりに、以前のクエリの結果をSession変数にスローしました。それから、ソートするときが来たら、それを引き出してソートし、Sessionに送り返しました。

コードは次のとおりです。

  • 最初にそれをセッションに投げました

        goliath = (From f In wholeResults _
                      Group f By f.v_patient Into Group _
                      Order By v_patient.last_name, v_patient.first_name, v_patient.date_of_birth _
                      Select New With {.PatientID = v_patient.patient_id, .LastName = v_patient.last_name, .FirstName = v_patient.first_name, _
                         .DOB = v_patient.date_of_birth, .Ins = v_patient.insname, .MatchCount = Group.Count(), .Matches = Group}).ToList()
    
    Session("ListOfMatches") = goliath
    GroupMatchListView.DataSource = goliath
    
  • それから私は魔法をかけました

    Protected Sub GroupMatchListView_Sorting(sender As Object、e As System.Web.UI.WebControls.ListViewSortEventArgs)Handles GroupMatchListView.Sorting

            Dim interimMatches As IEnumerable(Of Object) = CType(Session("ListOfMatches"), IEnumerable(Of Object))
    
            Select Case e.SortExpression
                Case "LastName"
                    If CurrentSortExpression = "LastName" Then
                        interimMatches = interimMatches.Reverse()
                    Else
                        interimMatches = interimMatches.OrderBy(Function(i) CType(i.LastName, String)).ToList()
                        CurrentSortExpression = "LastName"
                    End If
                Case "FirstName"
                    If CurrentSortExpression = "FirstName" Then
                        interimMatches = interimMatches.Reverse()
                    Else
                        interimMatches = interimMatches.OrderBy(Function(i) CType(i.FirstName, String)).ToList()
                        CurrentSortExpression = "FirstName"
                    End If
                Case "DOB"
                    If CurrentSortExpression = "DOB" Then
                        interimMatches = interimMatches.Reverse()
                    Else
                        interimMatches = interimMatches.OrderBy(Function(i) CType(i.DOB, Date)).ToList()
                        CurrentSortExpression = "DOB"
                    End If
                Case "Ins"
                    If CurrentSortExpression = "Ins" Then
                        interimMatches = interimMatches.Reverse()
                    Else
                        interimMatches = interimMatches.OrderBy(Function(i) CType(i.Ins, String)).ToList()
                        CurrentSortExpression = "Ins"
                    End If
            End Select
            Session("ListOfMatches") = interimMatches
            ViewState("CurrentSortExpression") = CurrentSortExpression
            GroupMatchListView.DataSource = interimMatches
            GroupMatchListView.DataBind()
    
        End Sub
    

これが誰かを助けることを願っています。

于 2012-04-23T05:06:39.257 に答える