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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:09:00+00:00 2026-05-15T13:09:00+00:00

I have a web application (with C#). I have a GridView and want to

  • 0

I have a web application (with C#). I have a GridView and want to be able to sort its contents. I have added the tags

…

AllowSorting="True"
onsorting="MyGridView_Sorting">

and

asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME" 

inside the GridView. I have implemented the MyGridView_Sorting method. Thing is: it does not work. Does nothing. The header text “Name” looks like an active link, but clicking produces no effect. Putting a break point inside

MyGridView_Sorting

shows that it actually never goes inside the function. What is wrong? What do I miss?

Thanks!!!

Sep

< asp:GridView ID="MyGridView"
runat="server"                               
CssClass="pvgrid" 
Width="90%" 
AutoGenerateColumns="false"
OnRowCommand="MyGridView_RowCommand"
AllowPaging="True" 
PageSize="10" 
AllowSorting="True"
onsorting="MyGridView_Sorting" 
onpageindexchanging="MyGridView_PageIndexChanging" >

< Columns >
< asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME"  />
< /Columns >
< /asp:GridView >


protected void MyGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    MyGridView.PageIndex = e.NewPageIndex;
    MyGridView.DataBind();
}

protected void MyGridView_Sorting(object sender, GridViewSortEventArgs e)
{
    DataTable dataTable = MyGridView.DataSource as DataTable;

    if (dataTable != null)
    {
        DataView dataView = new DataView(dataTable);
        dataView.Sort = e.SortExpression + " "+ ConvertSortDirectionToSql(e.SortDirection);
        MyGridView.DataSource = dataView;
        MyGridView.DataBind();
    }
}
  • 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-15T13:09:01+00:00Added an answer on May 15, 2026 at 1:09 pm

    GridView delegates sorting to underlying DataSource. GridView does not perform sorting on its own, it just delegates. So you need to look into your DataSource for sorting. What is the DataSource ? What kind of Data does it display ? Are those custom objects coming from ObjectDataSource or you’re using SqlDataSource or LinqDataSource ?

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

Sidebar

Related Questions

I have a GridView and want to on an ASP.NET Web Application page and
Does anyone have a solution/link for copying contents of a GridView/Datatable (web application aspx)to
I have a web application that is becoming rather large. I want to separate
I have a web application using ASP.NET 2.0 and I want to know if
I have this web application that has grown to an unmanageable mess. I want
in my web application i have grid view control with edit property true. Now
i have gridview in my asp.net web application under framework 3.5. I am binding
I have two Gridview in my Web application.I need ,while clicking the (ExcelExpot) button
in web application, i have a gridview in that each row contain 3 textboxes
I have a VB.NET / ASP.NET web application. I added a dropdownlist into FooterTemplate

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.