Ticket Q201546
Visible to All Users

SaveClientLayout and initial sorting

created 16 years ago

Hi there -
I apply initial sorting to ASPxGridView like below:
<Columns>
    <dxwgv:GridViewDataTextColumn Caption="Name" FieldName="Name" SortOrder="Ascending" />
    …
</Columns>
Inside the Page_Load method I call the grdiview's SaveClientLayout method which returns me the following string: "version1|page1|visible5|t0|t1|t2|t3|t4|width5|e|e|e|e|e". You see there is no information about sorting, why? After switching to the next page of the gridview the SaveClientLayout method returns "version1|page2|sort1|a0|visible5|t0|t1|t2|t3|t4|width5|e|e|e|e|e". Now there IS info about sorting here. Why is that?

Show previous comments (5)
DevExpress Support Team 16 years ago

    Hi Maxim,
    The ASPxGridView sets column sorting in its OnLoad method (that also fires the Load event). This behavior is by design. But, the ASPxGridView.Load event fires after the Page_Load event.
    So, you can save the correct (with sort directions) client layout in the page's OnLoadComplete event handler:

    C#
    protected override void OnLoadComplete(EventArgs e) { base.OnLoadComplete(e); report("In Page_Load: " + (!IsPostBack ? "(for the first time) " : string.Empty) + ASPxGridView1.SaveClientLayout()); }

    This also works if the ASPxGridView is not bound to a data source.
    I have modified your sample. It is attached.
    Thanks,
    Serge D

    ?
    Unknown 16 years ago

      Bad. You try to convince me to call the method only when a particular event fires. But it should work equally always. Layout is layout whether the gridview is bound or not.

      DevExpress Support Team 16 years ago

        Hi Maxim,
        This behavior of ASPxGridView is explained by the following - the ASPxGridView doesn't set the sorting state of its columns on initialization (the ASPxGridView.Init event). The column sorting state is saved in the view state, which is restored later - in the ASPxGridView.Load event. So, if you get or set column sorting in the Page_Load event handler, which is raised before ASPxGridView.Load, this can cause unpredictable behavior.
        Thanks,
        Serge D

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.