Back to Devexpress

GridViewExtension.CreatePrintableObject(GridViewSettings, Object) Method

aspnetmvc-devexpress-dot-web-dot-mvc-dot-gridviewextension-dot-createprintableobject-x28-devexpress-dot-web-dot-mvc-dot-gridviewsettings-system-dot-object-x29.md

latest4.6 KB
Original Source

GridViewExtension.CreatePrintableObject(GridViewSettings, Object) Method

Enables a GridView to be printed using the XtraPrinting Library.

Namespace : DevExpress.Web.Mvc

Assembly : DevExpress.Web.Mvc5.v25.2.dll

NuGet Package : DevExpress.Web.Mvc5

Declaration

csharp
public static IBasePrintable CreatePrintableObject(
    GridViewSettings settings,
    object dataObject
)
vb
Public Shared Function CreatePrintableObject(
    settings As GridViewSettings,
    dataObject As Object
) As IBasePrintable

Parameters

NameTypeDescription
settingsGridViewSettings

An object that contains GridView settings.

| | dataObject | Object |

The GridView’s data source (typically, it is passed to the grid’s GridViewExtension.Bind method).

|

Returns

TypeDescription
IBasePrintable

An interface that allows you to print GridView data.

|

Remarks

csharp
public ActionResult Export()  
{  
    var ps = new PrintingSystem();  
    var link = new PrintableComponentLink(ps);  
    link.Component = GridViewExtension.CreatePrintableObject(GetSettings(), DataProvider.GetData().ToList());  
    // ...
    return result;  
}

Note

Note that the BeforeExport property is not in effect if you use the CreatePrintableObject method. Instead, use the GridViewExtension.ExportTo[FormatName] methods to export data.

To apply the grid’s client state, the grid should be placed in a form.

cshtml
@using (Html.BeginForm("ReportGenerator", "Home")) {
    @Html.DevExpress().Button(settings => {
        settings.Name = "reportGenerator";
        settings.Text = "Generate Report";
        settings.UseSubmitBehavior = true;
    }).GetHtml()
    @Html.Partial("GridViewPartialView", Model)
}
csharp
public ActionResult ReportGenerator() {
    XtraReport_GridView report = new XtraReport_GridView();
    report.AssignGridPrintable(
        GridViewExtension.CreatePrintableObject(GetGridViewSettings(), NorthwindDataProvider.GetCustomers())
    );            
    return View("ViewReport", report );
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreatePrintableObject(GridViewSettings, Object) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-mvc-grid-export-multiple-gridviews-into-a-document/CS/Controllers/HomeController.cs#L32

csharp
categoriesGridSettings.Columns.Add("Description");
link1.Component = GridViewExtension.CreatePrintableObject(categoriesGridSettings, MyModel.GetCategories());

asp-net-mvc-grid-export-multiple-gridviews-into-a-document/VB/Controllers/HomeController.vb#L37

vb
categoriesGridSettings.Columns.Add("Description")
link1.Component = GridViewExtension.CreatePrintableObject(categoriesGridSettings, MyModel.GetCategories())

See Also

Grid View

GridViewExtension Class

GridViewExtension Members

DevExpress.Web.Mvc Namespace