I have several columns which I've sorted but the Date Field sorts as a string
rather than as a date and I can't seem to figure out how to fix that.
Below is my code.
Thanks for your help.
public partial class MyProjects : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session["SortExpression"] = "";
Session["SortDirection"] = "";
}
SDU.Service_Class.DataService ds =
new SDU.Service_Class.DataService(Request.ApplicationP ath,
"ProMan", SDU.Service_Class.DataService.QueryType.STORED_PRO C,
"p_get_projects");
if (ds.ExecuteCommand(30))
{
Session["MyProjects"] = ds.GetData.Tables[0];
gProjects.DataSource = (DataTable)Session["MyProjects"];
gProjects.DataBind();
foreach (GridViewRow row in gProjects.Rows)
{
//row.Cells.
}
}
gProjects.RowStyle.Height = 20;
{
String expression = "";
SortDirection direction;
}
}
protected void gProjects_Sorting(object sender,
GridViewSortEventArgs e)
{
DataView dv = new DataView((DataTable)Session["MyProjects"]);
string direction;
if (Session["SortExpression"].ToString() == e.SortExpression)
{
if (Session["SortDirection"].ToString() == "ASC")
{
direction = "DESC";
}
else
{
direction = "ASC";
}
}
else
{
direction = "ASC";
}
dv.Sort = e.SortExpression + " " + direction;
gProjects.DataSource = dv;
gProjects.DataBind();
Session["SortExpression"] = e.SortExpression;
Session["SortDirection"] = direction;
}