Quantcast
Viewing latest article 1
Browse Latest Browse All 10

Tip: Get report parameters as text from Crystal Reports in C#

I am starting a new set of posts presenting small code snippets in C# you could use when working with Crystal Reports in Visual Studio.

And the first one is “GetReportParamsAsText“. Very simple but very handy function which allows to include report parameters values in your ASP.Net page without actually displaying the report.
This version works only with Discrete Value parameters. 

/// Function returns list of paramaters descriptions with
/// associated values for specified report
public string GetReportParamsAsText(ReportDocument reportDocument)
{
    if (reportDocument == null) return "Report not specified";
    string result = "";
    string description;
    string valueText;
    ParameterDiscreteValue value;
    foreach (ParameterFieldDefinition prm
                  in reportDocument.DataDefinition.ParameterFields)
    {
        try
        {
            if (prm.CurrentValues.IsNoValue) continue;
            if (prm.CurrentValues[0] is ParameterDiscreteValue)
            {
                value = (ParameterDiscreteValue)prm.CurrentValues[0];
                if (description.StartsWith("Enter "))
                {
                    description = description.Remove(0, 6);
                }
                valueText = value.Value.ToString();
            }
            else
            {
                valueText = "[not supported param type]";
            }
            result += "<strong>" + description + "</strong> " + valueText + "
";
        }
        catch
        {
            // Ignore any errors
        }
    }
    return result;
}

Copyright © 2013 Serge's Technology View. This Feed is for personal non-commercial use only.

Viewing latest article 1
Browse Latest Browse All 10

Trending Articles