B
Brian Barnes
Hi,
I know this has been done quite often before, but all my research and trials
have not worked. Basically I am trying to display a sorted list of e-mail
Addresses in a datalist control (using web forms) from a dataset. The only
table in the dataset has 2 columns (UserID (Guid (defined as a string),
primary Key) and UserEmail (string)) and is filled from an Access database.
It is not practical to bring the data in sorted (although it is possible) as
it makes the SQL statement "hairy" (and I like to write clean code). Also I
doubt the speed gain (if any) will be negligible due to the small size I
expect the table to be.
My current code is:
datGroupAdmin.tblUser.DefaultView.Sort = "UserEmail"
lstGroupAdmin.DataSource = datGroupAdmin.tblUser
lstGroupAdmin.DataBind()
and does not show the list sorted.
I also have tried:
datGroupAdmin.tblUser.DefaultView.Sort = "UserEmail"
lstGroupAdmin.DataSource = datGroupAdmin.tblUser.DefaultView
lstGroupAdmin.DataBind()
again to no avail.
I have also tried implementing my own sort method:
tblClone = tblTest.Copy
tblTest.Clear()
While tblClone.Rows.Count > 0
rowLow = tblClone.Rows(0)
For Each row In tblClone.Rows
If row.Item(0).ToString.ToLower < rowLow.Item(0).ToString.ToLower
Then
RowLow = row
End If
Next
tblTest.Rows.Add(rowLow)
tblClone.Rows.Remove(row)
End While
but this came up with a runtime error "5" "This row already belongs to
another table" (I realise that this isn't the best sort method, it was a
test to see if I could get it to work).
At one stage, I believe I had the datatable sorted (but this did not display
sorted in the datalist - I'm sure I don't re-initialise the datatable or
datalist elsewhere).
I know this has been done quite often before, but all my research and trials
have not worked. Basically I am trying to display a sorted list of e-mail
Addresses in a datalist control (using web forms) from a dataset. The only
table in the dataset has 2 columns (UserID (Guid (defined as a string),
primary Key) and UserEmail (string)) and is filled from an Access database.
It is not practical to bring the data in sorted (although it is possible) as
it makes the SQL statement "hairy" (and I like to write clean code). Also I
doubt the speed gain (if any) will be negligible due to the small size I
expect the table to be.
My current code is:
datGroupAdmin.tblUser.DefaultView.Sort = "UserEmail"
lstGroupAdmin.DataSource = datGroupAdmin.tblUser
lstGroupAdmin.DataBind()
and does not show the list sorted.
I also have tried:
datGroupAdmin.tblUser.DefaultView.Sort = "UserEmail"
lstGroupAdmin.DataSource = datGroupAdmin.tblUser.DefaultView
lstGroupAdmin.DataBind()
again to no avail.
I have also tried implementing my own sort method:
tblClone = tblTest.Copy
tblTest.Clear()
While tblClone.Rows.Count > 0
rowLow = tblClone.Rows(0)
For Each row In tblClone.Rows
If row.Item(0).ToString.ToLower < rowLow.Item(0).ToString.ToLower
Then
RowLow = row
End If
Next
tblTest.Rows.Add(rowLow)
tblClone.Rows.Remove(row)
End While
but this came up with a runtime error "5" "This row already belongs to
another table" (I realise that this isn't the best sort method, it was a
test to see if I could get it to work).
At one stage, I believe I had the datatable sorted (but this did not display
sorted in the datalist - I'm sure I don't re-initialise the datatable or
datalist elsewhere).