Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:36:44+00:00 2026-06-02T08:36:44+00:00

So here’s the scenario – I started by querying data from tables transactions and

  • 0

So here’s the scenario – I started by querying data from tables transactions and v_patients. I execute that query to a List(Of transaction). I manipulate (Concat(), GroupBy(), etc.) that list until I reach a final projection and DataBind() to GroupMatchListView. I have some LinkButtons in the markup that have Sort commands. Now I need to write something in the GroupMatchListView_Sorting event handler that sorts the list. I think I need to use either an IComparer, or GroupMatchListView.Items.OrderBy somehow to sort the ListView, but I’m baffled. I do not want to run another SQL Query and redo my list manipulations. Thanks for any help!

The final projection:

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()

I have some buttons that have sort commands:

<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>

The place where I put the sort logic:

 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

Thanks again.

EDIT: I think I’m on the right track. I take GroupMatchListView.Items, use OrderBy, and assign the results to a List(Of ListViewDatItems). Then I clear the GroupMatchListView.Items, and add the items back from my list of ListViewDataItems. However, when I go back to the page, nothing has changed. If I use just DataBind() I get an empty ListView. If I assign the list of ListViewDataItems as the DataSource, then DataBind, I get an error. Anybody know how I can wrap this up?

Here’s what I’ve worked out:

    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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:36:45+00:00Added an answer on June 2, 2026 at 8:36 am

    Well, I couldn’t do it with GroupMatchesListView.Items. Instead, I threw the results of my earlier query into a Session variable. Then when it came time to sort, I pulled it out, sorted it, and sent it back to Session.

    Here’s the code:

    • First I threw it into 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
      
    • Then I worked my magic

      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
      

    Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is a scenario: User installs .NET application that you have made. After some
Here is my query: select word_id, count(sentence_id) from sentence_word group by word_id having count(sentence_id)
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes
Here's some CSS and HTML to make a textarea below a list of data
Here is a complete example. I want to forbid using A::set from objects casted
Here's the deal: I'm in the process of planning a mid-sized business application that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.