Answer: With the help of Datatable DefaultView property we can convert any Datatable into Dataview.
DataView is used for sorting and filtering purposes.
If we want to sort rows based on condition,then we will use DataView Sort method.
For ex:-
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Rows.Add("1", "Vishal");
dt.Rows.Add("2", "Rajesh");
dt.Rows.Add("3", "Prashant");
dt.Rows.Add("4", "Dharmesh");
dt.Rows.Add("5", "Nitin");
DataView dv = dt.DefaultView;
dv.Sort = "ID desc";
We can also Sort using datatable rows with Linq or DataTable'Select method.
But as Dataview is more efficient way to do this.
Asked In: Many Interviews |
Alert Moderator