Answer: With the help of DataView' ToTable() method we can convert
DataView back to DataTable.
For ex:-
As we know that,DataView is used for sorting and filtering purposes.
Sometimes,we do not have an Order By clause in the query,so we have such functionality with the help of Dataview Sort property.
For Example:-
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 = "Name Desc";
DataTable dt_new = dv.ToTable();
Gridview1.DataSource = dt_new;
Gridview1.DataBind();
Asked In: Many Interviews |
Alert Moderator