Re-Sorting a filtered Datagrid

M

Michelle

I've looked everywhere and haven't found anybody with the same problem I am facing.

I load a datagrid upon open the web page with data. I have soting by asc/desc working when the user clicks the datagrid headers.

The users can also select filtering criteria via dropdowns on the web form. I take that criteria, run a SQL statement and bind the datagrid with the results.

Now how do I allow sorting on this filtered data? When the users click the datagrid headers the sorting reverts back to re-sorting all rows that were returned on the page_load not the current, filtered view of the dataset.

My DataGrid1_SortCommand code is as follows:

Dim dg As DataGrid = DataGrid1
Dim StrSort = dg.Attributes("SortExpression")
Dim StrASC = dg.Attributes("SortASC")
dg.Attributes("SortExpression") = e.SortExpression
dg.Attributes("SortASC") = "yes"

If e.SortExpression = StrSort Then
If StrASC = "yes" Then
dg.Attributes("SortASC") = "no"
Else
dg.Attributes("SortASC") = "yes"
End If
End If

Dim dt As DataTable = DsLMSProductListings1.Tables(0)
Dim dv As DataView = New DataView(dt)
dv.Sort = dg.Attributes("SortExpression")

If dg.Attributes("SortASC") = "no" Then
dv.Sort &= " DESC"
End If
dg.CurrentPageIndex = 0
SqlDataAdapter1.Fill(DsLMSProductListings1)
dg.DataSource = dv
dg.DataBind()

Thanks in advance for any suggestions!

From http://www.developmentnow.com/g/7_2004_10_8_0_0/dotnet-framework-adonet.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
M

midgetgem

Does anyone have any answers for this? I'm struggling with the same
problem, wanting a simple way to sort just the rows that are in the
datagrid after filtering.

Thanks in advance

Gemma
I've looked everywhere and haven't found anybody with the same problem I am facing.

I load a datagrid upon open the web page with data. I have soting by
asc/desc working when the user clicks the datagrid headers.
The users can also select filtering criteria via dropdowns on the web
form. I take that criteria, run a SQL statement and bind the datagrid
with the results.
Now how do I allow sorting on this filtered data? When the users
click the datagrid headers the sorting reverts back to re-sorting all
rows that were returned on the page_load not the current, filtered view
of the dataset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top