Back to Devexpress

How to: Save and Restore the ASPxGridView's Layout

aspnet-4268-components-grid-view-examples-how-to-save-and-restore-the-aspxgridviews-layout.md

latest2.7 KB
Original Source

How to: Save and Restore the ASPxGridView's Layout

  • Dec 17, 2020
  • 2 minutes to read

Example 1

This example shows how to save or restore the ASPxGridView layout to or from a data store.

csharp
protected void ASPxGridView1_ClientLayout(object sender, 
DevExpress.Web.ASPxClientLayoutArgs e) {
    if (e.LayoutMode == DevExpress.Web.ClientLayoutMode.Saving) {
        SaveUserLayoutToDatabase(userID, "AccountGrid", e.LayoutData);
    }
    else {
        if (System.IO.File.Exists(fileName))
            e.LayoutData = RestoreUserLayoutFromDatabase(userID, "AccountGrid");
    }
}
vb
Protected Sub ASPxGridView1_ClientLayout(sender As Object,_
e As DevExpress.Web.ASPxClientLayoutArgs)
   If e.LayoutMode = DevExpress.Web.ClientLayoutMode.Saving Then
      SaveUserLayoutToDatabase(userID, "AccountGrid", e.LayoutData)
   Else
      If File.Exists(fileName) Then
         e.LayoutData = RestoreUserLayoutFromDatabase(userID, "AccountGrid")
      End If
   End If
End Sub

Example 2

The example below shows how to save and restore the previously saved layout manually. When a user clicks the Save Layout or Load Layout button, the grid calls the ASPxClientGridView.PerformCallback method to send a callback to the server. This method raises the server-side ASPxGridView.CustomCallback event. Handle this event to save or restore the grid’s layout.

csharp
protected void ASPxGridView1_CustomCallback(object sender,
    DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e) {
    if (e.Parameters == "save") {
        SaveUserLayoutToDatabase("userID", "GridLayout", ASPxGridView1.SaveClientLayout());
    }
    if (e.Parameters == "load") {
        ASPxGridView1.LoadClientLayout(GetUserLayoutFromDatabase("userID", "GridLayout"));
    }
}
vb
Protected Sub ASPxGridView1_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewCustomCallbackEventArgs)
    If e.Parameters = "save" Then
        SaveUserLayoutToDatabase("userID", "GridLayout", ASPxGridView1.SaveClientLayout())
    End If

    If e.Parameters = "load" Then
        ASPxGridView1.LoadClientLayout(GetUserLayoutFromDatabase("userID", "GridLayout"))
    End If
End Sub

Note

To specify which information on the ASPxGridView layout can be saved, use options provided by the ASPxGridView.SettingsCookies property.