views:

24

answers:

2

Hello,

i have the following method:

private DataTable getsortedtable(DataTable dt)
{
    dt.DefaultView.Sort = "Name desc";
    //I would need to return the datatable sorted.
}

My issue is that i cannot change the return type of this method and i have to return a DataTable but i would like return it sorted.

Are there any magic hidden property of dt.DefaultView to return the dt sorted?

Thanks a lot in advance.

Best Regards.

+1  A: 

do this

private DataTable getsortedtable(DataTable dt)
{
    //do the operation for sort   
    return dataView.ToTable();
}
anishmarokey
Thanks Anishmarokey!
Josemalive
+2  A: 
 private DataTable getsortedtable(DataTable dt)
 {
    dataview v=dt.defaultview;
    v.sort="columnName DESC";
    dt=v.toTable();
    return dt;
  }
FosterZ
Thanks a lot Foster.
Josemalive