Solved

Sorting a GridView

Posted on 2009-07-11
6
574 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now