473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

bidirectional sort with datagrid

Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting attribute?

FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid2.SortCommand
Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub
Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function
Nov 18 '05 #1
4 1421
Very good example:
http://aspnet.4guysfromrolla.com/articles/012903-1.aspx

"DC Gringo" wrote:
Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting attribute?

FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid2.SortCommand
Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub
Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function

Nov 18 '05 #2
Here's a good example for you:
http://www.dotnetjunkies.com/HowTo/B...0D57699C3.dcik

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting
attribute?

FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid2.SortCommand
Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub
Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function

Nov 18 '05 #3
Another example
http://www.dotnetbips.com/displayarticle.aspx?id=7

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting attribute?
FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid2.SortCommand
Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub
Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function

Nov 18 '05 #4
Thank you...

The problem I have with this example is it makes me manually enter the
Select Cases for each column. I'm looking for something that will
dynamically update with changes in the datagrid columns?

' Figure out the column index
Dim iIndex As Integer
Select case ColumnToSort.toUpper()
case "AU_FNAME"
iIndex = 0
case "AU_LNAME"
iIndex = 1
case "STATE"
iIndex = 3
End Select

_____
DC G
"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Very good example:
http://aspnet.4guysfromrolla.com/articles/012903-1.aspx

"DC Gringo" wrote:
Can someone show me how to turn this into a bi-directional sort allowing
ascending and descending using the default datagrid allowsorting attribute?
FYI, Session("source") is an sqldataadapter
------------

Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid2.SortCommand
Dim ds As DataSet = GetDataSource()
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = e.SortExpression

DataGrid2.DataSource = dt.DefaultView
DataGrid2.DataBind()

End Sub
Protected Function GetDataSource() As DataSet

Dim ds As New DataSet
Dim da As New SqlDataAdapter
da = Session("Source")
da.Fill(ds)
Return ds

End Function

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
Is there an event that is invoked when a user sorts a column in a Windows Forms DataGrid? I have context senstive icons that are enabled\disabled depending upon the selected item in the...
5
by: Bill Todd | last post by:
In a WinForms application with a DataGrid bound to a DataTable, if I change the DefaultDataView.Sort property the order of the data in the grid does not change. If I change the Sort property...
4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
2
by: Snig | last post by:
Hi, I want to sort the DataGrid according to the number of clicks of mouse on the column-header link. e.g. if user clicks on the header once - it will be sorted ASC if the header is...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
4
by: mark | last post by:
i have populated a datagrid succesfully and enabled sort successfully except its not bidirectional - how do i do this ? this is my code for sorting Private Sub DataGrid1_SortCommand(ByVal...
5
by: Kurt Schroeder | last post by:
I'm using VS.net. I have created a component with the basic set of database commands. This component returns a record set that is bound to a datagrid. I want to add a dynamic sort, but am not sure...
2
by: shuckjunkmail | last post by:
It was suggested that I re-submit this question as a new post rather than adding onto an old and unanswered post. The basic problem has to do with the .NET datagrid and sorting. I am having...
8
by: Mateusz Ɓoskot | last post by:
Hi, I know iterator categories as presented by many authors: Stroustrup, Josuttis and Koenig&Moo: Input <---| |<--- Forward <--- Bidirectional <--- Random Output <---|
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.