Solved

Sorting a GridView

Posted on 2009-07-11
6
586 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

832 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