aspnet-devexpress-dot-web-dot-aspxgridview-142fc76b.md
Fires before a column is sorted or grouped.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event ASPxGridViewBeforeColumnGroupingSortingEventHandler BeforeColumnSortingGrouping
Public Event BeforeColumnSortingGrouping As ASPxGridViewBeforeColumnGroupingSortingEventHandler
The BeforeColumnSortingGrouping event's data class is ASPxGridViewBeforeColumnGroupingSortingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Column | Gets a column whose sort or group order has been changed. |
| OldGroupIndex | Gets the column’s previous position among grouped columns. |
| OldSortIndex | Gets a column’s (row’s for ASPxVerticalGrid) previous position among sorted columns (rows). Inherited from ASPxGridBeforeColumnGroupingSortingEventArgs. |
| OldSortOrder | Gets a column’s (row’s for ASPxVerticalGrid) previous sort order. Inherited from ASPxGridBeforeColumnGroupingSortingEventArgs. |
The BeforeColumnSortingGrouping event allows you to perform custom actions before a column is sorted or grouped.
In the example below, the control raises the BeforeColumnSortingGrouping event to change the column visibility.
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False"
KeyFieldName="ProductID" OnBeforeColumnSortingGrouping="grid_BeforeColumnSortingGrouping">
<Columns>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Name="VisibleProductName" FieldName="ProductName" VisibleIndex="1">
<Settings AllowGroup="True" SortMode="Custom" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Name="InvisibleProductName" FieldName="ProductName" VisibleIndex="2"
Visible="False" />
<dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2" />
</Columns>
<Settings ShowGroupPanel="True" />
</dx:ASPxGridView>
protected void grid_BeforeColumnSortingGrouping(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewBeforeColumnGroupingSortingEventArgs e) {
if(e.Column.Name == "VisibleProductName")
grid.Columns["InvisibleProductName"].Visible = ((grid.Columns["VisibleProductName"] as GridViewDataColumn).GroupIndex != -1);
}
Protected Sub grid_BeforeColumnSortingGrouping(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewBeforeColumnGroupingSortingEventArgs)
If e.Column.Name = "VisibleProductName" Then grid.Columns("InvisibleProductName").Visible = ((TryCast(grid.Columns("VisibleProductName"), GridViewDataColumn)).GroupIndex <> -1)
End Sub
See Also