Groups | Blog | Home
all groups > asp.net > march 2004 >

asp.net : Sorting a datagrid without using a DataSet


Patrick Delifer
3/19/2004 7:38:45 PM

Hi,
Does anyone know if I can sort a DataGrid without using a dataset?

I am using an ArrayList to Databind in my datagrid. The ArrayList is
returned from a server object(that queries the DB).

All the exAamples I see on the net use a dataset. Is there any other way
of doing it? Can I use a DataView object without a Dataset?

Thanks.
Patrick


*** Sent via Developersdex http://www.developersdex.com ***
Patrick Delifer
3/19/2004 9:18:22 PM

HI Andrew,

yes I can sort the ArrayList (I can do it in my stored procedure) but
then I want the user to be able to sort using different header columns
(i.e Name, Address, Status,etc .


*** Sent via Developersdex http://www.developersdex.com ***
Bill Borg
3/19/2004 9:51:06 PM
Turn on "allow sorting" on the grid, user can click on a column to sort, behind each column you've assigned "sortexpression", in OnSortCommand (vb speak) use sortexpression to decide how to sort the arraylist, and then rebind the arraylist to the datagrid. I just tried it with a trivial example, but it worked fine

----- Patrick Delifer wrote: ----


HI Andrew

yes I can sort the ArrayList (I can do it in my stored procedure) bu
then I want the user to be able to sort using different header column
(i.e Name, Address, Status,etc


*** Sent via Developersdex http://www.developersdex.com **
Don't just participate in USENET...get rewarded for it
Manohar Kamath [MVP]
3/19/2004 11:10:21 PM
Actually, it does not matter how you create your dataview, or datatable that
binds to the datagrid. You just need to sort those objects upon clicking
sort (by adding an event handler)

myDataGrid.SortCommand += new
DataGridSortCommandEventHandler(myDataGrid_Sort);

private void myDataGrid_Sort(object source, DataGridSortCommandEventArgs e)
{
// Create your Data table here
// You can sort it as you create it

// Bind your dataview/datatable here
myDataGrid.DataSource = myDataTable;
myDataGrid.DataBind();
}


--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


[quoted text, click to view]

Andrew de la Harpe
3/20/2004 4:06:01 PM
Can you not just sort the ArrayList before binding ?
Maybe the server object should have a SortBy property ?
A
[quoted text, click to view]

AddThis Social Bookmark Button