シナリオは次のとおりです。テーブルtransactions
とv_patients
からデータをクエリすることから始めました。そのクエリをList(Of transaction)
に実行します。私は最終的な投影に達するまで(Concat()
、GroupBy()
など)リストを操作し、GroupMatchListViewにはDataBind()
を操作します。私はSort
コマンドを持つマークアップにいくつかのLinkButtonを持っています。今度は、リストを並べ替えるイベントハンドラに何かを書く必要があります。私はどちらかIComparer、またはGroupMatchListView.Items.OrderBy
何とかListViewをソートする必要があると思うが、私はうんざりしています。私は、別のSQLクエリを実行し、私のリストの操作をやり直したくありません。助けてくれてありがとう!カスタムプロジェクションでDataBoundされたASP.NETリストビューを並べ替える
最終投影:
<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
感謝を
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()
私は、ソートコマンドを持っているいくつかのボタンがあります。
編集:私は正しい道にいると思う。私は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