[DataTable]コントロールソートイベントでDataViewおよびDataTableでソート

6244 ワード

        DataView DataTable  

    :.net   

  ASP.NET     ,     dataset(  DataTable),   DataGrid GridView        

,        fids       。             DataView DataTable      .



        DataView  ,      :



DataView dv = dt.DefaultView; 

dv.Sort = "dis,     desc"; 



 



   dv   DataGird  。



       ,          ,    ,    ViewState         .       

   DataTable DataSet,

DataView        , DataView  Table        ,          .







              (         ):





private DataTable SortTable(DataTable dt,string[] pids) { DataTable dt0 = dt.Clone(); //      

for(int i=0;i<pids.Length;i++) { if(pids[i] != string.Empty) { DataRow[] drs = dt.Select("pos_id=" +

pids[i]); if(drs.Length > 0) { foreach(DataRow dr in drs) { dt0.ImportRow(dr); //    } } } }

return dt0; } 





  :          , datatable      ,        。



           ,          20,000,000   ,       .



   ,    .NET    DataRow[]         CopyToDataTable      DataTable    

,               :



C#    

string currentSortColumn = this.SortColumn;//  ViewState        

this.SortColumn = e.SortExpression;   

  

if (currentSortColumn == this.SortColumn)   

    this.SortAscending = !this.SortAscending;//  ViewState        

else  

    this.SortAscending = false;   

  

DataTable dt = (DataTable)ViewState["DataSource"];   

DataRow[] filter = dt.Select("",this.SortColumn + " " + (this.SortAscending? "ASC" : "DESC"));   

DataTable newTable = filter.CopyToDataTable();   

ViewState["DataSource"] = newTable;   

this.BindDateGrid();  



string currentSortColumn = this.SortColumn;//  ViewState     

this.SortColumn = e.SortExpression;



if (currentSortColumn == this.SortColumn)

    this.SortAscending = !this.SortAscending;//  ViewState     

else

    this.SortAscending = false;



DataTable dt = (DataTable)ViewState["DataSource"];

DataRow[] filter = dt.Select("",this.SortColumn + " " + (this.SortAscending? "ASC" : "DESC"));

DataTable newTable = filter.CopyToDataTable();

ViewState["DataSource"] = newTable;

this.BindDateGrid();



  



       CopyToDataTable        .