Sorting Datefield in a DataView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WandaLL
    New Member
    • Jan 2007
    • 2

    #1

    Sorting Datefield in a DataView

    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.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {


    if (!Page.IsPostBa ck)
    {
    Session["SortExpression "] = "";
    Session["SortDirect ion"] = "";
    }
    SDU.Service_Cla ss.DataService ds =
    new SDU.Service_Cla ss.DataService( Request.Applica tionPath,
    "ProMan", SDU.Service_Cla ss.DataService. QueryType.STORE D_PROC,
    "p_get_projects ");
    if (ds.ExecuteComm and(30))
    {
    Session["MyProjects "] = ds.GetData.Tabl es[0];
    gProjects.DataS ource = (DataTable)Sess ion["MyProjects "];
    gProjects.DataB ind();
    foreach (GridViewRow row in gProjects.Rows)
    {
    //row.Cells.
    }
    }
    gProjects.RowSt yle.Height = 20;
    {


    String expression = "";
    SortDirection direction;


    }
    }
    protected void gProjects_Sorti ng(object sender,
    GridViewSortEve ntArgs e)
    {
    DataView dv = new DataView((DataT able)Session["MyProjects "]);
    string direction;
    if (Session["SortExpression "].ToString() == e.SortExpressio n)
    {
    if (Session["SortDirect ion"].ToString() == "ASC")
    {
    direction = "DESC";
    }
    else
    {
    direction = "ASC";
    }
    }
    else
    {
    direction = "ASC";
    }


    dv.Sort = e.SortExpressio n + " " + direction;
    gProjects.DataS ource = dv;
    gProjects.DataB ind();
    Session["SortExpression "] = e.SortExpressio n;
    Session["SortDirect ion"] = direction;
    }
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Are you formatting the date anywhere? Please give an example of the dates sorting by string, so that we know exaclty what you mean... :).

    Comment

    • WandaLL
      New Member
      • Jan 2007
      • 2

      #3
      I'm using a GridView and I have a date column and the dates are being pulled from a database:

      <asp:BoundFie ld DataField="DueD ate" HeaderText="Due Date" SortExpression= "DueDate">
      <HeaderStyle HorizontalAlign ="Left" />
      <ItemStyle HorizontalAlign ="Left" Width="90" />
      </asp:BoundField>

      Comment

      Working...