How to display data of BizForm for print

   —   
This article shows how to display data of BizForm for print, i.e. how to display them as labels
Please follow procedure bellow:

1) Create alternative form for your BizForm. Set all required fields to use Label as 'field type'

2) Create copy of BizForm web part

3) Edit code behind of this copied web part. Add following method into it:

    // checks if record with given ID exists in BizForm
    protected bool RecordExists(int formRecordID)
    {
        string bizFormName = this.BizFormName;
        string siteName = viewBiz.SiteName;
        bool Result = false;

        // Get BizForm definition
        BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);

        if (bfi != null)
        {
            // Get data type definition
            DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);
            if (dci != null)
            {
                // Get all bizform data
                GeneralConnection genConn = ConnectionHelper.GetConnection();
                // Get the record with specified ID
                DataClass formRecord = new DataClass(dci.ClassName, formRecordID, genConn);

                if (!formRecord.IsEmpty())

                    Result = true;

            }
        }
        return Result;
    }


4) Add following marked code into SetupControl() method of this web part:

    /// <summary>
    /// Initializes the control properties
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do nothing
        }
        else
        {
            // Set BizForm properties
            viewBiz.FormName = this.BizFormName;
            viewBiz.SiteName = this.SiteName;
            viewBiz.UseColonBehindLabel = this.UseColonBehindLabel;
            viewBiz.AlternativeFormFullName = this.AlternativeFormName;
            viewBiz.ValidationErrorMessage = this.ValidationErrorMessage;

            int formRecordID = QueryHelper.GetInteger("recordId", 0);
            if ((formRecordID > 0) && (RecordExists(formRecordID)))
            {
                viewBiz.ItemID = formRecordID;
            }

            
            // Set the live site context
            if (viewBiz.BasicForm != null)
            {
                viewBiz.BasicForm.ControlContext.ContextName = CMS.SiteProvider.ControlContext.LIVE_SITE;
            }
        }
    }


5) Add copied web part to some page and set it to use alternative form from step 1. Add following code into 'Content before' field:

<div class="printForm">

and following code into 'Content after' field:

</div>

6) Add following style declaration into your stylesheet (it should hide the submit button for this form):

.printForm .FormButton
{
  display: none;
}

7) Open the page with ID of appropriate record in query string, e.g.: http://localhost/testBizFormPrint.aspx?recordId=1


See also:

Applies to: Kentico CMS 5.0
Share this article on   LinkedIn Google+