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 663121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:27:16+00:00 2026-05-13T23:27:16+00:00

What should I do to perform the sorting in grid view? Please help

  • 0

What should I do to perform the sorting in grid view?

Please help

  • 1 1 Answer
  • 1 View
  • 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-13T23:27:16+00:00Added an answer on May 13, 2026 at 11:27 pm

    You can implement code like the following:

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
         DataTable dataTable = GridView1.DataSource as DataTable;
    
         if (dataTable != null)
         {
              DataView dataView = new DataView(dataTable);
              dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
    
              GridView1.DataSource = dataView;
              GridView1.DataBind();
         }
    }
    
    private string ConvertSortDirectionToSql(SortDirection sortDirection)
    {
         string newSortDirection = String.Empty;
    
         switch (sortDirection)
         {
              case SortDirection.Ascending:
                  newSortDirection = "ASC";
              break;
    
              case SortDirection.Descending:
                  newSortDirection = "DESC";
              break;
         }
    
         return newSortDirection;
    }
    

    With this code, your GridView definition should read:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowSorting="true" OnSorting="GridView1_Sorting">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="People Names" SortExpression="Name" />
        <asp:BoundField DataField="Age" HeaderText="People Ages" SortExpression="Age" />
    </Columns>
    </asp:GridView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should I use NHibernate Collection Cascading to perform collection save-updates, or should I use
It seems like I should be able to perform bit shift in C/C++ by
I would like to perform a key event detection in textbox. The keys should
I'm writing a windows service that should perform an action every, lets say, 60
I am a neophyte of opencv. I should perform operations for a project involving
I'm writing small utility app (JBoss Netty based) which should perform some trivial login
I have been given the following code that should perform an ssl handshake and
I wanna write a program that should perform some tasks automatically if someone logs
I'm building an android app which should perform a GET on my site to
I'm developing an application that should perform certain sql queries in different MSSQL servers

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.