Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:04:01+00:00 2026-06-16T01:04:01+00:00

I am using ASP.NET and C#.This is my code. private const string ASCENDING =

  • 0

I am using ASP.NET and C#.This is my code.

    private const string ASCENDING = "ASC"; 
    private const string DESCENDING = "DESC";
    public SortDirection GridViewSortDirection 
    {     
        get     
        {         
            if (ViewState["sortDirection"] == null)             
                ViewState["sortDirection"] = SortDirection.Ascending;          
            return (SortDirection) ViewState["sortDirection"];                     
        }     
        set { ViewState["sortDirection"] = value; }  
    }

    public string SortExpression
    {
        get
        {
            if (ViewState["sortExpression"] == null)
                ViewState["sortExpression"] = "JobNumber";
            return ViewState["sortExpression"] as string;
        }
        set { ViewState["sortExpression"] = value; }
    }
    protected void OnSorting(object sender, GridViewSortEventArgs e)
    {
            SortExpression = e.SortExpression;
            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridViewSortDirection = SortDirection.Descending;
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
            }
            BindGrid();
    }

I am applying sorting for all the columns and working fine. But with date column it is like in this order(dd/mm/yyyy).

  • 30/11/2012
  • 10/12/2012
  • 9/10/2012

    <asp:BoundField DataField="ReportedDate" HeaderText="Reported Date" SortExpression="ReportedDate" DataFormatString="{0:DD/MM/YYYY}" HtmlEncode="false" />
    

the datatype of this column is date.

How to do this?Am i doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:04:01+00:00Added an answer on June 16, 2026 at 1:04 am

    There are two options

    1.To sort at SQL Level,this is the best and proper method,bind the resulting resultset in to gridview.

    2.To bind a DataTable with the query output and run a sort on datatable,and then bind it to gridview.
    keep in mind to add datatype to datatable column accTable.Columns.Add("Date",typeof(DateTime));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.net MVC with C#. Why this is code: public IQueryable<Product> ListProducts(string
I am using ASP.NET to transmit a .jar file. This code works perfectly on
I'm using asp.net mvc4, simplemembership and EF. actually i have this code to search
I am using ASP.Net MVC but this probably applies to all MVC patterns in
[NOTE: I'm using ASP.NET MVC2 RC2.] I have URLs like this: /customers/123/orders/456/items/index /customers/123/orders/456/items/789/edit My
I am using ASP.NET Web Forms/C# . I am having this function in my
I wrote an application using ASP.NET MVC, in this application I have an Index
I'm using ASP.NET C# with database MYSQL, I follow this step on creating a
I'm developing a mobile oriented website using asp.net. This website will consume some web
Hi This is kind of peculiar requirement.. I am using asp.net and jQuery together

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.