Solved page sort query by selection

Posted on 2009-02-09
Last Modified: 2012-05-06
I am trying to sort a query in an page.
the page contains a grid (peopleid, contactname, contactcompany), populated by a query against the database, the grid is sortable by lastname, company.(clicking the header)
I create a button on the page that will refresh an other query that is filtered by the contactid selected in my grid (all the selected contactid separated by a comma are stored in a label)
see code 1
The second query looks like (see code 2)

I would like the system to order the second query in the same order as they are selected in the grid. So if by example, I order my grid by company and then select each people seprately, the second query result will keep the order of selection.
By the way, the system actually store each peopleid in the lblpeopleidtxt correctly, but fail to keep this order in the second query.

Thanks for your help
code 1

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        ' StringBuilder object 

        Dim str As New StringBuilder()

        Dim first As Boolean = True

        For i As Integer = 0 To GridView1.Rows.Count - 1


            ' Select the checkboxes from the GridView control 

            Dim row As GridViewRow = GridView1.Rows(i)

            Dim isChecked As Boolean = DirectCast(row.FindControl("chkSelect"), CheckBox).Checked


            If isChecked Then

                If first Then

                    first = False



                End If

                ' Column 2 is the name column 



            End If


        ' prints out the result 

        ' Response.Write(str.ToString())

        lblpeopleid.Text = str.ToString

    End Sub

code 2: the query


Open in new window

Question by:talentium
    LVL 15

    Expert Comment

    In the code that binds GridView2, you can add this bit of code after binding the data to it.

    GridView2.Sort(Gridview1.SortExpression, GridView1.SortDirection)

    Accepted Solution

    Thanks for reply,
    really interresting answer, As I use a datalist to show the result of the query (code 2)
    the idea could be the same as yours with something like keeping the sorting of gridview1 in the
    datalist1 based on the query selectedpeopleshortlist (see code of datalist 1 below)

    I need some help in the syntax, this could probably be done in the page load like in the code snippet,
    but when I try this I receive a msg that
    'Sort' si not a member of 'System.Web.UI.webcontrols.Datalist'

    code of the datalist 1
    <asp:DataList ID="DataList1" runat="server" DataSourceID="selectedpeopleshortlist" RepeatLayout="Flow"
                ShowFooter="False" ShowHeader="False" Width="95%">
    code for page load
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    DataList1.Sort = (Gridview1.SortExpression, GridView1.SortDirection)
      End Sub

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now