One way to sort two-way sorting in DataGrid

xiaoxiao2021-03-06  14

Although DataGrid in .NET has sorted features, bidirectional sorting is not supported. Used, I have seen some relevant posts, I tried a way, I actually get it, huh, huh.

It is mainly to save a parameter with DataGrid.attribute, and modify the sortexpression of DataGridColumn in OnSortCommand. The code is as follows:

Private void binddata () {dataable dt = .......; if (dt! = null) {dataView DV = DT.defaultView; if (DataGrid1.attributes ["sortby"]! = null) {DV.SORT = DataGrid1.attributes ["sortby"];

DataGrid1.datasource = DV; DataGrid1.DATABIND ();}}

Private void DataGridsort (Object Source, System.Web.ui.WebControls.DataGridsortCommandeventArgs E) {dataGrid1.attributes ["sortby"] = sortstr; this.binddata ();

/ / Find the column of sort and modify the sorting properties of it

DataGridColumn CLM = NULL;

For (int i = 0; i

IF (CLM == null) return; if (e.Sortexpression.tolower (). Indexof ("DESC")> 0) {clm.sortexpression = E.Sortexpression.tolower (). Replace ("DESC", "ASC" } Else {if (e.Sortexpression.tolower (). Indexof ("ASC")> 0) {clm.sortexpression = E.Sortexpression.tolower (). Replace ("ASC", "DESC");} else {Clm.sortexpression = e.sortexpression.tolower () "desc";}}}

转载请注明原文地址:https://www.9cbs.com/read-49545.html

New Post(0)