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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:02:36+00:00 2026-05-17T21:02:36+00:00

I had Grid view and I added property allow sorting in it and I

  • 0

I had Grid view and I added property allow sorting in it and I converted all fields in grid view to item template and after that this error appeared (The GridView ‘GridView1’ fired event sorting which wasn’t handled)
Please anyone help me
.

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

‘>

  • 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-17T21:02:36+00:00Added an answer on May 17, 2026 at 9:02 pm

    If you are not binding your GridView to SqlDataSource and you are setting its AllowSorting to true, you need to do sorting manually. You need to assign sorting event to the GridView, and write your own code to implement the sorting. You can refer to the code below, and modify accordingly.

    On aspx page:

    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        onsorting="GridView1_Sorting">
    </asp:GridView>
    

    On codebehind:

    public partial class GridViewSort : System.Web.UI.Page
    {
        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; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
                return;
    
            GridView1.DataSource = GetStaff();
            GridView1.DataBind();
        }
    
    
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
    
            string sortExpression = e.SortExpression;
    
            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridViewSortDirection = SortDirection.Descending;
                SortGridView(sortExpression, DESCENDING);
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                SortGridView(sortExpression, ASCENDING);
            }   
        }
    
        private void SortGridView(string sortExpression, string direction)
        {
            DataTable dt = GetStaff();
    
            DataView dv = new DataView(dt);
            dv.Sort = sortExpression + direction;
    
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
    
        /// <summary>
        /// Dummy data
        /// </summary>
        /// <returns></returns>
        private DataTable GetStaff()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Age", typeof(int));
    
            for (int i = 1; i <= 20; i++)
            {
                dt.Rows.Add(i, "Staff - " + i, 20 );
            }
    
            return dt;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had grid view which bind sql data source and added field to update
I had to delete all the rows from a log table that contained about
I have a data grid in a view that is bound to a List
I had a grid view populated from dataset and I have to redirect another
If I had a label on a view that I wanted to have the
I have a ASP.NET/VB that had a GridView to display a list of users
A discussion happened today where a grid containing data, which ultimately had data attached
Had a coworker ask me this, and in my brain befuddled state I didn't
I had a discussion with some colleagues mentioning that there are not too many
I had the idea of a search engine that would index web items like

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.