Sorting by a string parameter

Posts   
 
    
un.real
User
Posts: 12
Joined: 27-May-2005
# Posted on: 19-Jul-2005 12:23:04   

hello guys;

I am using a typedList to fill my datagrid. what I want to do is to sort the datagrid according to user's selection. (You know; users may click on a column header on a datagrid and trigger the sortCommand event for the datagrid.)

I want to do something like this:


//DATAGRID SORTCOMMAND EVENT HANDLER
private myDataGrid_SortCommand(Object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
  GridListFiller([colorvalue="0011FF"]e.SortExpression[/color]);
}

//THE FUNCTION THAT FILLS THE TYPEDLIST
private sometableTypedList GridListFiller([colorvalue="0011FF"]string sortField[/color])
{
   sometableTypedList Tlist = new sometableTypedList();

   ISortExpression sorter = new SortExpression();
   sorter.Add([colorvalue="0011FF"]sortField[/color], SortOperator.Descending);

   Tlist.Fill(0,sorter,false,null);

   return Tlist;

}

please help me simple_smile thanks in advance. abdullah.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Jul-2005 11:28:10   

If you want to sort the typedlist after it's loaded, it should support sorting automatically, as the typedlist is a datatable, which is bound to the grid using its default DataView, which supports sorting out of the box. So if you allow sorting in the grid (by enabling the grid's sorting ability, you have to do that manually in most grids), you can sort the typedlist in the grid by clicking on a column header.

I think that's what you want to do, if I understand you correctly, or am I mistaken?

Frans Bouma | Lead developer LLBLGen Pro
un.real
User
Posts: 12
Joined: 27-May-2005
# Posted on: 20-Jul-2005 18:11:53   

that's what I exactly want to do. I am using .NET 2003's native datagrid. I enable sorting for my datagrid from the property builder of it. I also assing the sorting field for each column.

after these process, column headers become links. (so we click them to sort out the data) but these links doesn't work. it needs some extra code. (in the SortCommand Events though)

. . . I got it working now... simple_smile

thanks Otis wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Jul-2005 19:09:08   

Ok simple_smile

Frans Bouma | Lead developer LLBLGen Pro
MacDennis avatar
MacDennis
User
Posts: 50
Joined: 03-May-2005
# Posted on: 21-Jul-2005 15:09:37   

Please post your solution so others can benefit from it when they are searching these forums.

Thanks!

un.real
User
Posts: 12
Joined: 27-May-2005
# Posted on: 22-Jul-2005 13:21:35   

sure


                this.someTableCollection1 = myfunc();// fills the collection
                this.someTableCollection1 .SupportsSorting=true;
                this.someTableCollection1 .Sort(e.SortExpression, ListSortDirection.Descending, null);
                this.DataGrid1.DataBind();


someTableTypedList1 = myfunc();//fills the typedList
someTableTypedList1.DefaultView.Sort = e.SortExpression+" DESC";
DataGrid1.DataBind();

you have to write these code pieces into your datagrid's SortCommand event handler.