Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataGrid Sorting Problem

DataGrid Sorting Problem

Scheduled Pinned Locked Moved ASP.NET
cssalgorithmshelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sonia_basangar
    wrote on last edited by
    #1

    Hi ALL of you. i use view state for sorting code is given but problem is that it sorts perfectly on name but not on date .. What to do???? actually i chage the date into varchar in order to display in drid For Ex it shows 01 Feb 2007 in Grid but when i click on header it dont sort in correct way.. Bind(); oColumnCollection=dgHistory.Columns; if(ViewState["SortOrder"].ToString() == "" || ViewState["SortOrder"].ToString() == "DESC") { dv.Sort = e.SortExpression; // oCol.HeaderText = oCol.HeaderText + " (ASC)"; ViewState["SortExpression"]= e.SortExpression + "ASC"; ViewState["SortOrder"] = "ASC"; } else { dv.Sort = e.SortExpression + " DESC"; // oCol.HeaderText = oCol.HeaderText + " (DESC)"; ViewState["SortExpression"]= e.SortExpression + " DESC"; ViewState["SortOrder"] = "DESC"; } dgHistory.DataBind(); Thanks

    R C 2 Replies Last reply
    0
    • S sonia_basangar

      Hi ALL of you. i use view state for sorting code is given but problem is that it sorts perfectly on name but not on date .. What to do???? actually i chage the date into varchar in order to display in drid For Ex it shows 01 Feb 2007 in Grid but when i click on header it dont sort in correct way.. Bind(); oColumnCollection=dgHistory.Columns; if(ViewState["SortOrder"].ToString() == "" || ViewState["SortOrder"].ToString() == "DESC") { dv.Sort = e.SortExpression; // oCol.HeaderText = oCol.HeaderText + " (ASC)"; ViewState["SortExpression"]= e.SortExpression + "ASC"; ViewState["SortOrder"] = "ASC"; } else { dv.Sort = e.SortExpression + " DESC"; // oCol.HeaderText = oCol.HeaderText + " (DESC)"; ViewState["SortExpression"]= e.SortExpression + " DESC"; ViewState["SortOrder"] = "DESC"; } dgHistory.DataBind(); Thanks

      R Offline
      R Offline
      RSArockiam
      wrote on last edited by
      #2

      For date sorting, you have to use some different logic, especially date sorting is the best one. But, here you are using just string sorting, so you won't get correct result. So, use date field in the dataview instead of changing into varchar (that is best way), and use format to display the date into the specified format. You can use the DataFormatString property in grid. For example: for bound column, ....asp:BoundColumn DataField="FieldName" DataFormatString="{0:dd MMM yyyy}" ..... I hope, you can get the answer from this.

      Regards R.Arockiapathinathan

      1 Reply Last reply
      0
      • S sonia_basangar

        Hi ALL of you. i use view state for sorting code is given but problem is that it sorts perfectly on name but not on date .. What to do???? actually i chage the date into varchar in order to display in drid For Ex it shows 01 Feb 2007 in Grid but when i click on header it dont sort in correct way.. Bind(); oColumnCollection=dgHistory.Columns; if(ViewState["SortOrder"].ToString() == "" || ViewState["SortOrder"].ToString() == "DESC") { dv.Sort = e.SortExpression; // oCol.HeaderText = oCol.HeaderText + " (ASC)"; ViewState["SortExpression"]= e.SortExpression + "ASC"; ViewState["SortOrder"] = "ASC"; } else { dv.Sort = e.SortExpression + " DESC"; // oCol.HeaderText = oCol.HeaderText + " (DESC)"; ViewState["SortExpression"]= e.SortExpression + " DESC"; ViewState["SortOrder"] = "DESC"; } dgHistory.DataBind(); Thanks

        C Offline
        C Offline
        Chetan Ranpariya
        wrote on last edited by
        #3

        Hi, Do not covnert you date column to varchar but set the DataFormatString property of the column in which you are displaying the date value. Design Time I hope this will help you. Thanks and Regards, Chetan Ranpariya

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups