2012-04-20 10 views
0

シナリオは次のとおりです。テーブルtransactionsv_patientsからデータをクエリすることから始めました。そのクエリをList(Of transaction)に実行します。私は最終的な投影に達するまで(Concat()GroupBy()など)リストを操作し、GroupMatchListViewにはDataBind()を操作します。私はSortコマンドを持つマークアップにいくつかのLinkBut​​tonを持っています。今度は、リストを並べ替えるイベントハンドラに何かを書く必要があります。私はどちらか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 

答えて

0

をまあ、私はGroupMatchesListView.Itemsでそれを行うことができませんでした。ここで

は、私が働いてきたものです。代わりに、私は以前のクエリの結果を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 
    
  • それを投げた後、私は

    サブGroupMatchListView_Sorting(オブジェクトとして送信者、システムとしての電子保護された私の魔法を働きました。 Web.UI.WebControls.ListViewSortEventArgs)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 
    

これは誰かを助けることを望みます。

関連する問題