Bellow is the code for the sorting but i am not getting the sort when I execute and click on the column header .
Error comes on numberDiv .

Help to correct the same code or provide a different code.


private void Sort_DataGrid(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
ViewState("numberDiv") = 1;

SqlConnection conSort = new SqlConnection("Data Source=AB2\\SQLEXPRESS;Initial Catalog=checkcon;Integrated Security=True");
SqlCommand comSort = new SqlCommand("SELECT * FROM EmpInfo", conSort);
comSort.CommandType = CommandType.Text;
SqlDataAdapter SortAdapter = new SqlDataAdapter(comSort);
DataSet ds = new DataSet();
SortAdapter.Fill(ds);
DataView dv = new DataView(ds.Tables["EmpInfo"]);
Two way sorting LOGIC
if ((numberDiv % 2) == 0)
dv.Sort = e.SortExpression + " " + "ASC";
else dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
GridView1.DataSource = dv;
GridView1.DataBind();

}