Current filter:
                                You should refresh the page.
                                Support Center

                                ASPxGridView - How to implement showing/hiding columns in the manner similar to ASPxPivotGrid

                                0

                                The example demonstrates how to implement showing/hiding ASPxGridView columns in the manner similar to ASPxPivotGrid. To accomplish this, perform the following steps:

                                1. Place the ASPxPopupMenu control on a page. Add two items with such names as "HideColumn" and "ShowHideList".

                                2. Handle the client-side ASPxClientGridView.ContextMenu event. Show a popup menu if a user clicks on the grid's header.

                                3. Handle the client-side ASPxClientPopupMenu.ItemClick event. Check on which item the user has clicked and perform proper manipulations. If an item's name is "HideColumn", perform a grid's callback via the ASPxClientGridView.PerformCallback method and pass the required column name. In the ASPxGridView.CustomCallback event handler hide a column whose name we can get using e.Parameters. If an item's name is "ShowHideList", show or hide the grid's CustomizationWindow.

                                See also:
                                How to show/hide grid columns via ASPxPopupMenu (client-side version)
                                How to show/hide grid columns via ASPxPopupMenu

                                You must  log in  or  register  to leave comments
                                Select file
                                • Default.aspx
                                • Default.aspx.cs
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2013 vol 1.4 - v2013 vol 2.9
                                • v2011 vol 2.8 - v2012 vol 2.16
                                <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
                                
                                <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxMenu" TagPrefix="dx" %>
                                
                                <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
                                <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
                                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                                <html xmlns="http://www.w3.org/1999/xhtml">
                                <head runat="server">
                                    <title></title>
                                </head>
                                <body>
                                    <script type="text/javascript">
                                        var colName;
                                        function OnItemClick(s, e) {
                                            if (e.item.name == 'HideColumn') {
                                                grid.PerformCallback(colName);
                                                colName = null;
                                            }
                                            else {
                                                if (grid.IsCustomizationWindowVisible())
                                                    grid.HideCustomizationWindow();
                                                else
                                                    grid.ShowCustomizationWindow();
                                            }
                                        }
                                
                                        function OnContextMenu(s, e) {
                                            if (e.objectType == 'header') {
                                                colName = s.GetColumn(e.index).fieldName;
                                                headerMenu.GetItemByName('HideColumn').SetEnabled((colName == null ? false : true));
                                                headerMenu.ShowAtPos(ASPxClientUtils.GetEventX(e.htmlEvent), ASPxClientUtils.GetEventY(e.htmlEvent));
                                            }
                                        }
                                    </script>
                                    <form id="form1" runat="server">
                                    <div>
                                        <dx:ASPxGridView ID="gvData" runat="server" AutoGenerateColumns="False" 
                                            DataSourceID="ads" KeyFieldName="ProductID" 
                                            ClientInstanceName="grid" oncustomcallback="gvData_CustomCallback">
                                            <Columns>
                                                <dx:GridViewCommandColumn VisibleIndex="0">
                                                    <EditButton Visible="True">
                                                    </EditButton>
                                                </dx:GridViewCommandColumn>
                                                <dx:GridViewDataTextColumn FieldName="ProductID" VisibleIndex="1">
                                                </dx:GridViewDataTextColumn>
                                                <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="2">
                                                </dx:GridViewDataTextColumn>
                                            </Columns>
                                            <SettingsCustomizationWindow Enabled="True" />
                                            <ClientSideEvents ContextMenu="OnContextMenu" />
                                        </dx:ASPxGridView>
                                        <asp:AccessDataSource ID="ads" runat="server" DataFile="~/App_Data/data.mdb"
                                            SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]"></asp:AccessDataSource>
                                        <br />
                                        <dx:ASPxPopupMenu ID="headerMenu" runat="server" ClientInstanceName="headerMenu">
                                            <Items>
                                                <dx:MenuItem Text="Hide column" Name="HideColumn">
                                                </dx:MenuItem>
                                                <dx:MenuItem Text="Show/hide hidden field list" Name="ShowHideList">
                                                </dx:MenuItem>
                                            </Items>
                                         <ClientSideEvents ItemClick="OnItemClick"/>
                                        </dx:ASPxPopupMenu>
                                    </div>
                                    </form>
                                </body>
                                </html>

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners