Sorting Data in a Dataset in ASP.NET

I have a custom class that takes LoginID, FirstName, Lastname as params and does the following.
1) Query Active Directory for any people that match any of the three values above.
2) Plug the search results into a dataset and return this dataset object.

In my ASPX page, I have a repeater control and three textfields to allow a user to enter a firstname, lastname, login ID that is passed to the custom class. When the user clicks the button, the code-behind code calls the custom class, performs the search and returns a dataset. I want to be able to sort this data, but the code I am using does not seem to work. Am I doing something wrong in the code?
'**PART OF CLASS THAT RETURNS DATASET POPULATED WITH DATA FROM AN ACTIVE DIRECTORY QUERY
Dim ds As New DataSet("ADSearchResults")
Dim table As New DataTable("tblSearchResults")
table.Columns.Add("LoginID", System.Type.GetType("System.String"))
table.Columns.Add("Fname", System.Type.GetType("System.String"))
table.Columns.Add("Lname", System.Type.GetType("System.String"))
 
Dim result As SearchResult
For Each result In searcher.FindAll()
    Dim dr As DataRow = table.NewRow()
    dr(0) = result.GetDirectoryEntry.Properties.Item("SAMAccountName").Value
    dr(1) = result.GetDirectoryEntry.Properties.Item("givenName").Value
    dr(2) = result.GetDirectoryEntry.Properties.Item("sn").Value
    table.Rows.Add(dr)
Next
 
table.DefaultView.Sort = "Lname, fname, loginID"
ds.Tables.Add(table)
return ds
 
 
 
 
'**ON PAGE LOAD IN THE CODE BEHIND FORM...
repGrid.DataSource = ds
repGrid.DataMember = "tblSearchResults"
repGrid.Visible = True
repGrid.DataBind()
 
 
 
 
'**REPEATER USED IN ASPX PAGE
		<asp:Repeater ID="repGrid" runat="server" Visible="False">
		<HeaderTemplate>
		 <table border="1">
		  <tr>
		   <th>Login ID</th>
		   <th>Fname</th>
		   <th>Lname</th>
		  </tr>
		 </HeaderTemplate>
		<ItemTemplate>
		 <tr>
		  <td><%# DataBinder.Eval(Container, "DataItem.LoginID") %></td>
		<td><%# DataBinder.Eval(Container, "DataItem.Fname") %></td>
		<td><%# DataBinder.Eval(Container, "DataItem.LName") %></td>		  
		 </tr>
		</ItemTemplate>		
		<FooterTemplate>
		</table>
		</FooterTemplate> 
		</asp:Repeater>

Open in new window

PiedmontHealthAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

samtran0331Commented:
I think what's happening is that when this runs:

table.DefaultView.Sort = "Lname, fname, loginID"
ds.Tables.Add(table)
return ds


yes, you've sorted the defaultview of the table, but what gets added to the ds is still the raw (unsorted) table, not the defaultview.

you can either:
1. make the function return a dataview
or
2. don't sort the table until right before you bind it
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PiedmontHealthAuthor Commented:
I see. I have since read about the difference in DataSet and DateView. Makes sense. I changed the custom class to return a dataview of the dataset and in my codebehind, I did this...

        Dim dv As DataView = [RESULTING DATAVIEW FROM THE OBJECT CALL]
        repGrid.DataSource = dv
        repGrid.DataMember = "tblSearchResults"
        repGrid.Visible = True
        dv.Sort = "lname, fname, loginID"
        repGrid.DataBind()
Works like a champ. Thanks! I am slowly but surely getting this .NET stuff. ;)
0
PiedmontHealthAuthor Commented:
I love this site! I have thrown away my bailing pail!
0
samtran0331Commented:
since your function returns a dv, you can skip the extra "dim dv"

'Dim dv As DataView = [RESULTING DATAVIEW FROM THE OBJECT CALL]
repGrid.DataSource = FunctionThatReturnsADataview

btw, I think I worked with a former co-worker (or guy you replaced)...let's call him "Bob J. The Funny Guy"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.