473,382 Members | 1,717 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,382 software developers and data experts.

datagrid bidirectional sorting

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 source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but im
not sure how

thanks

mark
Nov 18 '05 #1
4 1368
you are correct. all you have to do is..
keep a session variable holding asc or desc and next time when clicked,
toggle between asc and desc.

its Order by columnname asc/desc

Av.

"mark" <ma**@remove.com> wrote in message news:eADzc.45$yu4.8@newsfe5-win...
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 source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but
im
not sure how

thanks

mark

Nov 18 '05 #2
Mark,

'Create a sort variable.

Dim Sort As String

'Check if sort is in viewstate
If Not ViewState.Item("Sort") Is Nothing Then
Sort = ViewState.Item("Sort")
'Toggle the sort
If Sort = "ASC" Then
Sort = "DESC"
Else
Sort = "ASC"
End If
Else
'First sort is ascending
Sort = "ASC"
End If

'Then tack it on to the select.

Dim sql As String = "SELECT * FROM extensionlist ORDER BY" &
e.SortExpression & " " & Sort

'Store the current sort in viewstate (or elsewhere for postback)
ViewState.Add("Sort", Sort)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"mark" <ma**@remove.com> wrote in message news:eADzc.45$yu4.8@newsfe5-win...
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 source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but im not sure how

thanks

mark

Nov 18 '05 #3
thanks for the replies - i thought it was a viewstate thing!

mark
Nov 18 '05 #4
Hi Mark,

you may like to read this article

http://www.dotnetjunkies.com/Article...9F55C72C..dcik

Regards
Ashish M Bhonkiya

"mark" <ma**@remove.com> wrote in message news:eADzc.45$yu4.8@newsfe5-win...
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 source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
DataGrid1.SortCommand
Dim strConn As String = connectionstring
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "SELECT * FROM extensionlist ORDER BY " &
e.SortExpression
Dim da As New System.Data.sqlclient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
conn.Close()
Label5.Text = e.SortExpression
End Sub

i know its something to do with adding DESC and ASC to the sql string but im
not sure how

thanks

mark
Nov 18 '05 #5

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

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
3
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
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: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
3
by: Mark Gilkes | last post by:
Hi, I have an aspx page in which I am building a DataGrid control in the code-behind dynamically. The DataGrid is declared along with BoundColumns and bound to the datasource, then added to a...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.