When i try to sort my table manually, i receive this error: DataTable must be set prior to using DataView. The code is:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable sourceTable = GridView1.DataSource as DataTable;
DataView view = new DataView(sourceTable);
string[] sortData = Session["sortExpression"]!= null ? Session["sortExpression"].ToString().Trim().Split(' ') : null;
if (sortData != null && e.SortExpression == sortData[0])
{
if (sortData[1] == "ASC")
{
view.Sort = e.SortExpression + " " + "DESC";
Session["sortExpression"] = e.SortExpression + " " + "DESC";
}
else
{
view.Sort = e.SortExpression + " " + "ASC";
Session["sortExpression"] = e.SortExpression + " " + "ASC";
}
}
else
{
view.Sort = e.SortExpression + " " + "ASC";
Session["sortExpression"] = e.SortExpression + " " + "ASC";
}
}
Where i wrong?