Example T1020324
Visible to All Users

Reporting for ASP.NET MVC - Create a Custom Report Control

This example demonstrates how to create a custom report control and add it to the End-User Report Designer toolbox.

Custom Report Controls in the Toolbox

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

CustomControlExample/CustomControls/MyControl.cs
C#
using DevExpress.Utils.Serializing; using DevExpress.XtraPrinting; using DevExpress.XtraReports.Localization; using DevExpress.XtraReports; using DevExpress.XtraReports.UI; using System.ComponentModel; using System.Drawing; public enum MyEnum { One, Two, Three } public class MyControl : XRLabel { public static readonly SizeF InitSizeF = new SizeF(200, 50); [XtraSerializableProperty, DefaultValue(true), Favorite(true), SRCategory(ReportStringId.CatBehavior)] public bool BoolProp { get; set; } [XtraSerializableProperty, DefaultValue(MyEnum.One)] public MyEnum EnumProp { get; set; } [XtraSerializableProperty] public Item[] ArrayProp { get; set; } protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps) { base.PutStateToBrick(brick, ps); brick.Text = EnumProp.ToString(); } public class Item { [XtraSerializableProperty] public int PropA { get; set; } } }
CustomControlExample/CustomControls/NumericLabel.cs
C#
using DevExpress.Utils.Serializing; using DevExpress.XtraPrinting; using DevExpress.XtraReports.UI; using System.ComponentModel; public class NumericLabel : XRLabel { [Browsable(true), Bindable(false), Category("Data")] [XtraSerializableProperty] [DefaultValue("")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), EditorBrowsable(EditorBrowsableState.Always)] public int Number { get; set; } // Render the control in the Designer's Preview and in the document. protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps) { base.PutStateToBrick(brick, ps); brick.Text = this.Number.ToString(); } }
CustomControlExample/Views/Home/Index.cshtml
Razor
@using Reporting_AspNetMvc_Create_Custom_Control <script type="text/html" id="dxrd-svg-toolbox-numericlabel"> <svg viewBox="-2 -4 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g id="Layer_1" transform="translate(-2, -4)" style="enable-background:new 0 0 32 32"> <g id="Window"> <path d="M30, 10L30, 5C30, 4.5 29.5, 4 29, 4L3, 4C2.5, 4 2, 4.5 2, 5L2, 10L30, 10z" fill="#1177D7" class="Blue" /> </g> </g> <g id="Layer_1" transform="translate(-2, -4.00000095367432)" style="enable-background:new 0 0 32 32"> <g id="Window"> <path d="M28, 10L28, 26L4, 26L4, 10L2, 10L2, 27C2, 27.5 2.5, 28 3, 28L29, 28C29.5, 28 30, 27.5 30, 27L30, 10L28, 10z" fill="#727272" class="Black" /> </g> </g> </svg> </script> @Html.DevExpress().ReportDesigner(settings => { settings.Name = "ReportDesigner1"; settings.CustomControlTypes.AddRange(new[] { typeof(MyControl), typeof(NumericLabel) }); }).BindToUrl("TestReport").GetHtml()

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.