Solved

Sorting a GridView

Posted on 2009-07-11
6
603 Views
Last Modified: 2012-05-07
Hello,

I am using a GridView with the AllowSorting="True" and the method OnSorting="gv_Sorting" implemented.
Still, When trying to filter the table and keep the sorting:

if (ViewState["SortDirection"] != null)
            {
                if (ViewState["SortDirection"].ToString() == "Ascending")
                {
                    gv.Sort(ViewState["SortExp"].ToString(), SortDirection.Ascending);
                }
                else
                {
                     gv.Sort(ViewState["SortExp"].ToString(), SortDirection.Descending);
                }
            }

When reaching gv.Sort I get the exception: "The GridView 'gv'  fired event Sorting which wasn't handled."

Why is that happening?

Thanks
0
Comment
Question by:Relegence
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:stormist
ID: 24835302
try erasing and re-writing where you invoke the event. Make sure you press tab twice to fill in the event method that it takes you to your handler.
0
 

Author Comment

by:Relegence
ID: 24838021
I am creating the event in design mode.
I have removed it and added it again.
That didn't help.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24840194
How are you filtering the table?  Are you binding to an SqlDataSource, or a DataView?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Relegence
ID: 24843371
I am binding to a DataView, nased on a DataTable.
Here is the relevant code:

DataView dvTopFeed = new DataView(dt);
            gv.DataSource = dvTopFeed;
            gv.DataBind();

            if (ViewState["SortDirection"] != null)
            {
                if (ViewState["SortDirection"].ToString() == "Ascending")
                {
                   
                    gv.Sort(ViewState["SortExp"].ToString(), SortDirection.Ascending);
                }
                else
                {
                 
                    gv.Sort(ViewState["SortExp"].ToString(), SortDirection.Descending);
                }
            }
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24843524
If you are binding to a DataView, then set the DataView.Sort property instead:

    DataView dvTopFeed = new DataView(dt);
    dvTopFeed.Sort = ViewState["SortExp"].ToString();
    gv.DataSource = dvTopFeed;
    gv.DataBind();

0
 

Author Closing Comment

by:Relegence
ID: 31602529
Working great! thanks a lot!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question