Current filter:
                                You should refresh the page.
                                Support Center

                                How to use the BeforeExport event of a GridView Extension

                                0

                                This example demonstrates how to use the BeforeExport event to export custom (selected) columns of GridView to the PDF file.

                                You must  log in  or  register  to leave comments
                                Select file
                                • BeforeExport.cshtml
                                • BeforeExportPartial.cshtml
                                • HomeController.cs
                                • Northwind.cs
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2011 vol 1.6 - v2013 vol 2.9
                                @using DevExpress.Razor.Models
                                @using System.Web.UI.WebControls
                                @{
                                    ViewBag.Title = "Home Page";
                                }
                                
                                <script type="text/javascript">
                                    function ExportToPDF() {
                                        var names = GetSelectedItemsNames();
                                        if (!names) {
                                            alert("Choose columns to export");
                                            return;
                                        }
                                            
                                        document.getElementById("ExportColumnsNames").value = names;
                                        document.forms[0].submit();
                                    }
                                    function GetSelectedItemsNames() {
                                        var selectedItems = columnNames.GetSelectedValues();
                                        var result = "";
                                        for (var index = 0; index < selectedItems.length; index++) {
                                            result += selectedItems[index] + ";";
                                        }
                                        return result;
                                    }
                                </script>
                                
                                @{
                                    string[] exportColumnsNames = ViewData["ExportColumnsNames"] == null 
                                        ? new string[] { "FirstName", "LastName", "HireDate" } 
                                        : ViewData["ExportColumnsNames"] as string[];
                                }
                                
                                @using (Html.BeginForm("ExportTo", "Home")) {
                                    <div style="padding: 10px;">
                                        <br />
                                        @Html.DevExpress().Button(settings => {
                                            settings.Name = "exportToPdf";
                                            settings.Text = "Export to PDF";
                                            settings.ClientSideEvents.Click = "function(s, e) { ExportToPDF(); }";
                                        }).GetHtml()
                                        @Html.Hidden("ExportColumnsNames", null)
                                    </div>
                                    <div style="float:left;">
                                        @Html.DevExpress().Label(settings => {
                                           settings.Name = "title";
                                           settings.Text = "Export columns: ";
                                        }).GetHtml()
                                    </div>
                                    <div style="float:left; padding-left: 10px; padding-right: 10px;">
                                        @Html.DevExpress().ListBox(settings => {
                                            settings.Name = "columnNames";
                                            settings.Properties.SelectionMode = ListEditSelectionMode.CheckColumn;
                                            settings.Height = Unit.Pixel(225);
                                       
                                            foreach(string name in NorthwindDataProvider.GetColumnsNames()){
                                                settings.Properties.Items.Add(name);
                                                settings.Properties.Items.FindByText(name).Selected = exportColumnsNames.Contains(name);
                                            }
                                        }).GetHtml()
                                    </div>
                                    <div>
                                        @Html.Partial("BeforeExportPartial", NorthwindDataProvider.GetEmployees())
                                    </div>
                                }

                                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