开发者

Gridview SortExpression with 2 fields

开发者 https://www.devze.com 2022-12-27 03:29 出处:网络
I have a GridView that get\'s its datasource from a complex object. So I\'m doing the Sorting & Paging in the code behind.

I have a GridView that get's its datasource from a complex object. So I'm doing the Sorting & Paging in the code behind.

<asp:GridView ID="SystemsDetailList" runat="server" AllowSorting="true" AllowPaging="true"
AutoGenerateColumns="False" ShowFooter="True" OnPageIndexChanging="gridView_PageIndexChanging" OnSorting="gridView_Sorting">

For an important title column I have a SortExpression with 2 fields:

SortExpression="FunctionalAreaDisplayCode, EswbsDisplayCode"

This in the code behind:

protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
    BindSystemList(e.SortExpression, sortOrder);
}

public string sortOrder
{
    get
    {
        if (ViewState["sortOrder"].ToString() == "desc")
            ViewState["sortOrder"] = "asc";

        else
            ViewState["sortOrder"] = "desc";

        return ViewState["sortOrder"].ToString();
    开发者_JAVA百科}
    set
    {
        ViewState["sortOrder"] = value;
    }
}

For some reason it will keep "FunctionalAreaDisplayCode" always sorted ASC but the EswbsDisplayCode works fine as it flips between ASC and DESC correctly.

and tips here?

thanks!


My guess is that it's creating an SQL ORDER BY clause by simply appending the Sort order to the sort expression. So you will have:

FunctionalAreaDisplayCode, EswbsDisplayCode asc

and

FunctionalAreaDisplayCode, EswbsDisplayCode desc

which are interpreted by SQL (or whatever is doing the sorting) as:

FunctionalAreaDisplayCode asc, EswbsDisplayCode asc

and

FunctionalAreaDisplayCode asc, EswbsDisplayCode desc

See this ORDER BY tutorial :

It’s important to remember that whenever you are ordering by more than one column, you need to specify ASC and/or DESC after each column

Hugh

0

精彩评论

暂无评论...
验证码 换一张
取 消