Sorting Datagrid

Z

Zamdrist

It's my understanding, in order to sort a datagrid you have to create a
new DataTable, correct?

So, if on the load of the page, you do something like this:

'adosDS & AdoConn are global in this instance
Dim adoSelect As New SqlCommand
Dim adoDa As New SqlDataAdapter

adoSelect.CommandType = CommandType.StoredProcedure
adoSelect.CommandText = "MG_SelectTMLSAssignments"
adoSelect.Connection = adoConn

adoDa.SelectCommand = adoSelect
adoDa.Fill(adoDS, "Assignments")
dgTMLSAssignments.DataSource = adoDS.Tables("Assignments").DefaultView
dgTMLSAssignments.DataBind()

You'd have to do the same thing essentially over again, in the
SortCommand event of the datagrid, correct?

The ASP.Net tutorial here:
http://www.asp.net/QuickStart/howto/doc/adoplus/FilterData.aspx says
you need only create a new dataview and set the Sort property, this
however doesn't work, generating the error: DataTable must be set prior
to using DataView

So...either I just don't get it, or Microsoft's example is incomplete
and/or erroneous.
 
P

Peter Johnson

Yes in essence you do have to retrieve your data in some way again, if
it is a small amount of data you could store it in session or in
viewstate instead of going back to your database everytime the page
postsback.

The datatable needs to be populated everytime you wish to create a
dataview of the data within it.

Microsofts example is incomplete for that.

Try looking at this full tutorial for your issue
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Regards,

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top