Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
As I am trying to sort the grid view by column
i have used sorting method to sort but shows error can anyone help help me

What I have tried:

public SortDirection dir
    {
        get
        {
            if (ViewState["dirstate"] == null)
            {
                ViewState["dirstate"] = SortDirection.Ascending;

            }
            return (SortDirection)ViewState["dirstate"];
        }
        set
        {
            ViewState["dirstate"] = value;
        }
    }
    protected void gvDetails_Sorting(object sender, GridViewSortEventArgs e)

    {

        string sortingDirection = string.Empty;

        if (dir == SortDirection.Ascending)
        {

            dir = SortDirection.Descending;

            sortingDirection = "Desc";

        }

        else

        {

            dir = SortDirection.Ascending;

            sortingDirection = "Asc";

        }
        DataView sortedView = new DataView(dt.gridview());

        sortedView.Sort = e.SortExpression + " " + sortingDirection;

        gvDetails.DataSource = sortedView;

        gvDetails.DataBind();

    }
Posted
Updated 8-Aug-17 22:05pm

1 solution

The error message is saying "The DataView constructor does not have an overloaded version which accepts a single parameter which is a GridView class instance"
It has overloads which accept no parameters, a DataTable, or a DataTable and some filter info: DataView Class (System.Data)[^] but it can't accept a GridView.

Probably, you want to pass the DataTable dt, but it's your app, not mine and I can't be sure.
 
Share this answer
 
Comments
Member 11644373 9-Aug-17 4:24am    
yes i want to pass
data table
OriginalGriff 9-Aug-17 4:35am    
So do ... you don't need me to tell you how to do that! :laugh:
Member 11644373 9-Aug-17 5:47am    
don't worry its done!:laugh:
OriginalGriff 9-Aug-17 6:03am    
:DYou'd be surprised just what some people need us to do for them ... it gets depressing sometimes!
Member 11644373 9-Aug-17 5:48am    
thankyou for your help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900