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

  • SEARCH
  • Home
  • 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 6334559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:40:59+00:00 2026-05-24T18:40:59+00:00

I have my SqlDataSource control. It basically has UpdateCommand and SelectCommand. My gridview is

  • 0

I have my SqlDataSource control. It basically has UpdateCommand and SelectCommand. My gridview is bound to this sqldatasource control. My SelectCommand is:

Select Username, Status from Users Order by LastLoginTime desc

I have my table something like this:

ABC IN PROGESS  somedate
DEF COMPLETE    somedate
PQR PENDING     somedate
JLM COMPLETE    somedate
LKM IN PROGESS  somedate

Currently query results are sorted by lastlogintime (i.e somedate). But I want my results to be sorted by 2nd column(say this column name is Status). I want the records to be sorted in such a way that 1st all users whole status is IN PROGRESS should appear then PENDING and then COMPLETE. As you can say this is not a simple order by clause.

How can I sort in this way with my SqlDataSource control?

  • 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-05-24T18:41:00+00:00Added an answer on May 24, 2026 at 6:41 pm

    You should use Custom Sort Order using CASE in SQL. Try this

    SELECT Name, Status FROM UsersOrder ORDER BY CASE Status
        WHEN 'IN PROGESS' THEN 1
        WHEN 'PENDING' THEN 2
        WHEN 'COMPLETE' THEN 3
        ELSE 99
    END
    

    So in effect your SelectCommand will be a hideous one-liner. 🙂

    SelectCommand="SELECT Name, Status FROM UsersOrder ORDER BY CASE Status WHEN 'IN PROGESS' THEN 1 WHEN 'PENDING' THEN 2 WHEN 'COMPLETE' THEN 3 ELSE 99 END" 
    

    I am afraid this is the only solution.

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

Sidebar

Related Questions

I have this situation where I have a SqlDatasource control and the select query
I have a SQLDataSource that is bound to a ListView control but I want
Simply, if I have a GridView with a SqlDataSource control declarative set as its
I have a gridview control in my c# program which currently has 12 columns
Background : I have a GridView which gets populated from an SqlDataSource via DataSourceID.
I have asp:GridView displaying client requests using asp:SqlDataSource . I want to limit displayed
I dream of creating a control which works something like this: <asp:SqlDataSource id=dsFoo runat=server
I have a User Control with a DetailsView that has the property AutoGenerateRows set
I have come across odd behavior involving nested gridview controls and row events. Basically
I have a gridview control inside another gridview control. When I click on the

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.