Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting a GridView

Posted on 2009-07-11
6
Medium Priority
?
620 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
Technology Partners: 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!

 

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 2000 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

Industry Leaders: 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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

782 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