//------ DATAVIEW FOR SORTING MILESTONE
private DataView Getdata()
{
connection();
amicassaCon.Open();
DataSet dsMilestone = new DataSet();
string strSelectCmd = "SELECT * FROM milestone ";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, amicassaCon);
da.Fill(dsMilestone, "milestone");
DataView dvMilestone = dsMilestone.Tables["milestone"].DefaultView;
dvMilestone.Sort = ViewState["SortExpr"].ToString();
return dvMilestone;
}
CODE AT PAGE LOAD
ViewState["SortExpr"] = Sort_Direction;
DataView dvMiles = Getdata();
GridView_milestone.DataSource = dvMiles;
GridView_milestone.DataBind();
protected void Sorting(object sender, GridViewSortEventArgs e)
{
string[] SortOrder = ViewState["SortExpr"].ToString().Split(' ');
if (SortOrder[0] == e.SortExpression)
{
if (SortOrder[1] == "ASC")
{
ViewState["SortExpr"] = e.SortExpression + " " + "DESC";
}
else
{
ViewState["SortExpr"] = e.SortExpression + " " + "ASC";
}
}
else
{
ViewState["SortExpr"] = e.SortExpression + " " + "ASC";
}
GridView_milestone.DataSource = Getdata();
GridView_milestone.DataBind();
}
Then allow sorting to the grid view and include the SortExpression="FIELDNAME" to each header :)