palehorse
Active member
- Joined
- Jan 28, 2005
- Messages
- 34
- Programming Experience
- 1-3
Hello everyone,
I have a datagrid that should be sorting two particular columns when the header is clicked. Well - one column is sorting fine - the other sorts fine up until the end and is out of order - but only when you get to the end of the list.
This is my code
Is this just an issue with the data in the db - or is my code wrong? Any suggestions would help. Let's just say the first_name field sorts everything fine (a-z) but towards the end (of about 200 names) lets say the last good sorted name is Zobo and after that it will show another name as Alexander when Alexander should be at the top - and after Alexander is Bobcat and then Charles - etc...so, it is in order 90% of the way - then starts back to the A's and goes in order again - does that make sense?
I have a datagrid that should be sorting two particular columns when the header is clicked. Well - one column is sorting fine - the other sorts fine up until the end and is out of order - but only when you get to the end of the list.
This is my code
VB.NET:
Private Function CreateDataSource()
Try
Dim sSQL As String = "SELECT uid_pk,first_name,last_name FROM customers"
Dim DA As SqlDataAdapter = New SqlDataAdapter(sSQL, CN)
Dim DS As New DataSet
DA.Fill(DS, "customers")
Dim DV As New DataView(DS.Tables("customers"))
DV.Sort = SortField
CreateDataSource = DV
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Function
Private Sub BindGrid()
Try
dg.DataSource = CreateDataSource()
dg.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub dg_Sort(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs) Handles dg.SortCommand
Try
SortField = e.SortExpression & " ASC"
BindGrid()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindGrid()
End If
End Sub
Is this just an issue with the data in the db - or is my code wrong? Any suggestions would help. Let's just say the first_name field sorts everything fine (a-z) but towards the end (of about 200 names) lets say the last good sorted name is Zobo and after that it will show another name as Alexander when Alexander should be at the top - and after Alexander is Bobcat and then Charles - etc...so, it is in order 90% of the way - then starts back to the A's and goes in order again - does that make sense?