Document Variables

The Bootstrap Rich Text Editor enables you to store custom information in the document using document variables. To insert a document variable in the document, use the DOCVARIABLE field code.

The DOCVARIABLE field code has the following syntax:

{ DOCVARIABLE "variable name" "argument1" "argument 2"... }

This field code inserts the value of a named document variable specified by a text in the field argument(s). Before a field is updated, the CalculateDocumentVariable server event is fired allowing you to manually calculate the required value. In a handler of this event, the event argument's Arguments property provides access to a collection of arguments contained within the field. A common task is to evaluate DOCVARIABLE fields in a document depending on the variable name and argument and then substitute fields with their values. Note that you can return a text or the entire Document as a document variable.

This demo illustrates how to use the DOCVARIABLE field with custom parameters to dynamically calculate and insert total incomes by categories and to embed bar charts that visualize income allocation by products.

<dx:BootstrapRichEdit runat="server" ActiveTabIndex="4" ShowConfirmOnLosingChanges="false"
    OnCalculateDocumentVariable="DemoRichEdit_CalculateDocumentVariable">
</dx:BootstrapRichEdit>
protected void DemoRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) {
    switch(e.VariableName) {
        case "Chart":
            var sales = GetSales(e.Arguments[0].Value);
            DocumentImageSource chart = DocumentImageSource.FromStream(CreateChart(sales));
            RichEditDocumentServer srv = new RichEditDocumentServer();
            srv.Document.Images.Append(chart);
            e.Value = srv.Document;
            e.Handled = true;
            break;
        case "CommonSales":
            var commonSales = GetCommonSales(e.Arguments[0].Value);
            e.Value = commonSales.ToString("C");
            e.Handled = true;
            break;
        default:
            break;
    }
}
IEnumerable<Sales_by_Category> GetSales(string categoryName) {
    return new NorthwindContextSL().SalesByCategory.Where(s => s.CategoryName == categoryName).ToList();
}
decimal GetCommonSales(string categoryName) {
    return GetSales(categoryName).Sum(s => s.ProductSales.Value);
}
Stream CreateChart(IEnumerable<Sales_by_Category> sales) {
    var cc = new WebChartControl();
    cc.Width = Unit.Pixel(600);
    cc.Height = Unit.Pixel(400);
    cc.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
    var series = new DevExpress.XtraCharts.Series("Products", DevExpress.XtraCharts.ViewType.Bar);
    series.DataSource = sales;
    series.ArgumentDataMember = "ProductName";
    series.ValueScaleType = DevExpress.XtraCharts.ScaleType.Numerical;
    series.ValueDataMembers.AddRange(new string[] { "ProductSales" });
    cc.Series.Add(series);
    Controls.Add(cc);
    cc.DataBind();
    MemoryStream stream = new MemoryStream();
    cc.ExportToImage(stream, DevExpress.Drawing.DXImageFormat.Png);
    stream.Position = 0;
    return stream;
}
Screen Size
Color Themes
Demo QR Code