The code below I am using to sort data in a datataable.. there are two different method I have tried and non of these methods actually work. Also order is DECS/ASC and colum is the index of the column I.E 10.
Does anyone have an idea to why this may be the case.
string[] tosort = sortval.Split('-');
string order = tosort[1];
int colum = Convert.ToInt32(tosort[0]);
DataView dv = new DataView();
DataTable dt = new DataTable();
dt = extractedData;
string columnName = dt.Columns[colum].ToString();
dt.DefaultView.Sort = columnName + " " + order;
// dv = dt.AsDataView();
// dv.Sort = dv.Table.Columns[colum].ColumnName + " " + order;
// dv.Sort = dv.Table.Columns[colum].ColumnName + " " + order;
// dt = dv.ToTable();
extractedData = dt;
Sorting doesn’t alter the order of the data in the
DataTableit is applicable to the view, so you should actually bind theDataViewlikedt.DefaultViewordt.DefaultView.ToTable();