當我嘗試手動對我的表進行分類時,我收到此錯誤: 必須在使用DataView之前設置DataTable。 代碼是:必須在使用DataView之前設置DataTable
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";
}
}
我在哪裏錯了?