[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

asp.net page sort query by selection

Hi,
I am trying to sort a query in an asp.net 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
                Else
                    str.Append(","c)
                End If
                ' Column 2 is the name column 
                str.Append(GridView1.Rows(i).Cells(1).Text)
                                
            End If
        Next
 
        ' prints out the result 
        ' Response.Write(str.ToString())
        lblpeopleid.Text = str.ToString
    End Sub
 
code 2: the query
SELECT PEOPLE.PEOPLEID, PEOPLE.FIRSTNAME,... from people where (',' || TO_CHAR(:PEOPLEID) || ',' LIKE '%,' || TO_CHAR(PEOPLE.PEOPLEID) || ',%')

Open in new window

0
talentium
Asked:
talentium
1 Solution
 
aibusinesssolutionsCommented:
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)
0
 
talentiumAuthor Commented:
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'

Thanks
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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now