How to move a DataTable row to the first position of its DataTable
asp.net, c#, dataset, datatable, linq
Solution
We have to clone the row data before:
DataRow[] dr = dtable.Select("column1 ='" + valueToSearch +"'");
DataRow newRow = dtable.NewRow();
// We "clone" the row
newRow.ItemArray = dr[0].ItemArray;
// We remove the old and insert the new
ds.Tables[0].Rows.Remove(dr[0]);
ds.Tables[0].Rows.InsertAt(newRow, 0);
Problem
I want to get a specific row on an asp.net DataTable and move it to be the first one onto this DataTable base on a column `column1` value. My Datatable `dt1` is populated via a DB query and the value to search is via another query from another DB so I don't know the value to search at the `dt1 select` time. ``` // I use this variable to search into // DataTable string valueToSearch = "some value"; ``` So I need to search the value `some value` into my DataTable in the column `column1`. and then move the entire row to the first position. Thank you.