I am trying to maintain sorting expression values while paging event of Grid.
But it takes null value in Viewstate ["Sort Expression"].ToString(); it throws object value not set to an a instance of object exception.
private DataView Getdata()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
DataSet dsEmployee = new DataSet();
string strSelectCmd = "SELECT [Emp_Name],[Emp_id],[Emp_job],[Emp_Dep],[Emp_Salary] FROM [employee]";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, conn);
da.Fill(dsEmployee, "Employee");
DataView dvEmp = dsEmployee.Tables["Employee"].DefaultView;
dvEmp.Sort = ViewState["SortExpr"].ToString();
return dvEmp;
}
}