ASPxGridBase.ClientLayout Event
Enables you to save and restore the previously saved layout of the grid.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.1.dll
NuGet Package: DevExpress.Web
Declaration
Event Data
The ClientLayout event's data class is ASPxClientLayoutArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
LayoutData | Gets or sets the layout data. |
LayoutMode | Indicates whether a control’s layout should be saved or restored. |
Remarks
Handle the ClientLayout event to save and restore the grid’s layout from a data store.
Save Layout
The event parameter’s ASPxClientLayoutArgs.LayoutMode property returns ClientLayoutMode.Saving. The ASPxClientLayoutArgs.LayoutData property contains the grid’s current layout that should be saved, for instance, to a database.
To control what information on the layout can be saved, use the options provided by the SettingsCookies property.
Restore Layout
- The ASPxClientLayoutArgs.LayoutMode property returns ClientLayoutMode.Loading. Read the grid’s layout data from a data store and assign it to the ASPxClientLayoutArgs.LayoutData property.
You can also save and restore the grid’s layout via the ASPxGridBase.SaveClientLayout and ASPxGridBase.LoadClientLayout methods.
Concept
Example: How to save or restore the ASPxGridView layout to or from a data store
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");
}
}
Example: How to keep the detail grids state after a master ASPxGridView layout is changed
<dx:ASPxGridView ID="MasterGrid" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
KeyFieldName="CategoryID" OnDetailRowExpandedChanged="MasterGrid_DetailRowExpandedChanged">
<Columns>
<dx:GridViewCommandColumn ShowClearFilterButton="True"/>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" >
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" />
<dx:GridViewDataTextColumn FieldName="Description" />
</Columns>
<Settings ShowFilterRow="True" ShowGroupPanel="True" />
<SettingsDetail ShowDetailRow="True" />
<Templates>
<DetailRow>
<dx:ASPxGridView ID="DetailGrid" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" KeyFieldName="ProductID"
OnBeforePerformDataSelect="DetailGrid_BeforePerformDataSelect"
OnClientLayout="DetailGrid_ClientLayout">
<Columns>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" >
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" />
<dx:GridViewDataTextColumn FieldName="CategoryID" />
<dx:GridViewDataTextColumn FieldName="UnitPrice" />
</Columns>
</dx:ASPxGridView>
</DetailRow>
</Templates>
</dx:ASPxGridView>
protected void Page_Init(object sender, EventArgs e) {
if (!IsPostBack)
Session.Clear();
}
protected void DetailGrid_BeforePerformDataSelect(object sender, EventArgs e) {
Session["CategoryID"] = ((ASPxGridView)sender).GetMasterRowKeyValue();
}
protected void DetailGrid_ClientLayout(object sender, DevExpress.Web.ASPxClientLayoutArgs e) {
ASPxGridView grid = sender as ASPxGridView;
string key = grid.GetMasterRowKeyValue().ToString();
if (e.LayoutMode == DevExpress.Web.ClientLayoutMode.Loading && Session["DetailGrid"+key] != null ) {
e.LayoutData = (string)Session["DetailGrid"+key];
}
else {
Session["DetailGrid"+key] = e.LayoutData;
}
}
protected void MasterGrid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e) {
if (e.Expanded == false) {
string key = MasterGrid.GetRowValues(e.VisibleIndex, MasterGrid.KeyFieldName).ToString();
Session["DetailGrid" + key] = null;
}
}