Telerik Forums
Reporting Forum
11 answers
171 views
Hi telerik,

I´m new in telerik's reporting and after created my report, I want create filters for that, for exemple, imagine that I have a list of products and I want filter them for Date or something else.

How I can do that? I cannot find any info about this in the internet.

Thanks for the help,
Manuel
Top achievements
Rank 1
 answered on 30 Dec 2011
1 answer
121 views
In the attached image, how do I resize all of the textboxes in the given row, when text wraps in one of the others?

Elian
Telerik team
 answered on 30 Dec 2011
3 answers
1.2K+ views

I have a generic ASCX control that uses the Telerik ReportViewer and I want to use that for all my reporting output. But, we run into the problem that we need to provide a Report object (as well as ReportParameters) to that viewer control. Here's how I did it:

1. In my case, I know my report assembly. With just a bit more work, the assembly itself could be passed in, but the following still uses reflection to load the report dynamically.

2. ReportParameters are passed in as "Name=Value;[Name=Value;...]" via a single public property named ReportParametersString. Not particularly extensible, but more than sufficient for my simple needs. I handle type coercion (that is, convert from string that is passed into ASCX parameter to specific type supported by Telerik) using the GetTypeFromReportType method. I also have (of course, we all do...) my own DAL (data access layer) using ADO.NET that can convert from just about any input type to any output type (not documented below).

3. In my report assembly, I purposely provide a dummy empty class to make getting the assembly type that much easier.

4. I assume that the report itself can handle its own datasource needs (more on that in another post--I cracked some code to get my own data connection string without needing to modify web.config which is owned by SharePoint not by me...).

5. My ASCX exposes a ReportName property that can be the absolute or relative class name of the report to load.

So here's the code, hope it's useful!

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ArchG2.Portal.rg2SupportingControls.Misc
{
 /// <summary>
 /// Generic reporting viewer for any Telerik report
 /// </summary>
 public partial class TelerikReportViewer : Utils.BaseManageableControl
 {
  private string _reportName;
  private string _prevReportName;
  private Telerik.Reporting.IReportDocument _report;
  private bool _pageIsLoaded;
  private string _reportParametersString;
  private Telerik.Reporting.ReportParameterCollection _reportParameters = new Telerik.Reporting.ReportParameterCollection();
  private TextBox _txtHeight;

  /// <summary>
  /// Handle a resize by applying the resize directly to the control
  /// </summary>
  protected override void resizeHandler()
  {
   if (Width != Unit.Empty)
   {
    // set an explicit width to the report
    rptvw.Width = Width;
   } //if
   if (Height != Unit.Empty)
   {
    // set an explicit height to the report
    rptvw.Height = Height;
   } //if
  } //resizeHandler

  /// <summary>
  /// Invoked whenever the report must definitely be set in the view control.
  /// Will force the view to update / take any other actions.
  /// </summary>
  private void setReport()
  {
   // access our stored report
   Telerik.Reporting.IReportDocument theReport = Report;
   if (theReport == null)
   {
    LH.warn("No report specified; cannot display");
    return;
   } //if

   // set the report itself in the managed viewer
   rptvw.Report = Report;
  } //setReport

  /// <summary>
  /// Given a Telerik reporting type, return a "real" object type so that we can
  /// perform type-safe coercion on data values
  /// </summary>
  /// <param name="reportType">The Telerik report type to convert</param>
  /// <returns>The OS type or an exception if this is an unknown type (new Telerik version could introduce this problem)</returns>
  private Type GetTypeFromReportType(Telerik.Reporting.ReportParameterType reportType)
  {
   switch (reportType)
   {
    case Telerik.Reporting.ReportParameterType.Boolean:
     return typeof(Boolean);
    case Telerik.Reporting.ReportParameterType.DateTime:
     return typeof(DateTime);
    case Telerik.Reporting.ReportParameterType.Float:
     return typeof(double);
    case Telerik.Reporting.ReportParameterType.Integer:
     return typeof(int);
    case Telerik.Reporting.ReportParameterType.String:
     return typeof(string);
    default:
     throw new ApplicationException(
      string.Format("Unknown report type: {0}", reportType.ToString())
     );
   } //switch
  } //GetTypeFromReportType

  /// <summary>
  /// Use reflection to load a given report object from the ArchG2.Reporting assembly.
  /// </summary>
  private void loadReport()
  {
   string flag = "";
   try
   {
    // leverage the Dummy class to get access to the ArchG2.Reporting assembly
    flag = "access_archg2_report";
    Type typeDummy = typeof(ArchG2.Reporting.Dummy);
    System.Reflection.Assembly assemblyArchG2Reporting = typeDummy.Assembly;

    // check to see if the user passed in a full path or a short path
    flag = "load_report";
    string reportToLoad = _reportName;
    int idxDot = reportToLoad.IndexOf('.');
    if (idxDot <= 0)
    {
     string prefix = assemblyArchG2Reporting.GetName().Name;
     if (idxDot < 0) prefix += ".";
     reportToLoad = reportToLoad.Insert(0, prefix);
    } //if
    LH.debug("Loading report ", reportToLoad, " (", _reportName, ")");
    Type typeOfDynamicReport = assemblyArchG2Reporting.GetType(reportToLoad);

    // now instantiate an object of the report; must have default ctor
    flag = "create_report";
    object oReport = Activator.CreateInstance(typeOfDynamicReport);

    // validate the report
    flag = "validate_report";
    Telerik.Reporting.IReportDocument theReport = oReport as Telerik.Reporting.IReportDocument;
    if (theReport == null) throw new ApplicationException("Invalid report type: " + typeOfDynamicReport.Name);

    // now set any parameters on the report
    if (ReportParameters.Count > 0)
    {
     // get the report list
     flag = "access_report_parms";
     List<Telerik.Reporting.ReportParameter> theParameters = theReport.ReportParameters.ToList();

     // build a dictionary
     Dictionary<string, Telerik.Reporting.ReportParameter> theDictionary = new Dictionary<string, Telerik.Reporting.ReportParameter>();
     foreach (Telerik.Reporting.ReportParameter parameter in theParameters)
     {
      theDictionary.Add(parameter.Name.ToUpper(), parameter);
     } //foreach

     // look up each item from input to the report itself
     flag = "iterate_source_parms";
     foreach (Telerik.Reporting.ReportParameter sourceParameter in ReportParameters)
     {
      // the specified source parameter must exist in the report
      string key = sourceParameter.Name.ToUpper();
      if (!theDictionary.Keys.Contains(key))
      {
       throw new ApplicationException(
        string.Format(
         "Source parameter {0} does not exist in report parameters",
         sourceParameter.Name
        )
       );
      } //if
      Telerik.Reporting.ReportParameter reportParameter = theDictionary[key];

      // do simple type coercion
      flag = "decode_parm_types";
      Type typeReport = GetTypeFromReportType(reportParameter.Type);
      Type typeSource = GetTypeFromReportType(sourceParameter.Type);

      // shortcut
      if (typeReport == typeSource)
      {
       // set value explicitly
       reportParameter.Value = sourceParameter.Value;
       continue;
      } //if

      // simple type coercion (exception on failure)
      flag = "convert_" + sourceParameter.Name;
      object oParameterValue = Abr.CodeLibrary.DataAccess.DataObject.DbObject(
       typeReport, sourceParameter.Value, false
      );
      reportParameter.Value = oParameterValue;
     } //foreach
    } //next

    // set the report
    Report = theReport;
   }
   catch (Exception ex)
   {
    LH.error("Problem at ", flag, ": ", ex);
    NotifyError("Report Problem: " + ex.Message);
   } //try
  } //loadReport

  /// <summary>
  /// The stored report for display within this viewer
  /// </summary>
  public Telerik.Reporting.IReportDocument Report
  {
   get { return _report; }
   set { _report = value; if (_pageIsLoaded) setReport(); }
  } //Report

  /// <summary>
  /// For control via the ASCX properties, allow a report name to be specified.
  /// This name should be the class name of the report in the ArchG2.Reporting
  /// module. This property uses reflection to load the report for display by the control.
  /// </summary>
  public string ReportName
  {
   get { return _reportName; }
   set { _prevReportName = _reportName; _reportName = value; }
  } //ReportName

  /// <summary>
  /// Return reference to the stored report parameter actual list.
  /// Useful to access from code (use ReportParametersString from ASCX).
  /// </summary>
  public Telerik.Reporting.ReportParameterCollection ReportParameters
  {
   get { return _reportParameters; }
  } //ReportParameters

  /// <summary>
  /// Pass in report parameters as a string; parsed with ; (semicolon)
  /// as delimiter. Use Name=Value;[Name=Value;...] format.
  /// </summary>
  public string ReportParametersString
  {
   get { return _reportParametersString; }
   set
   {
    string flag = "";
    try
    {
     // anything to do?
     flag = "validate_parms";
     _reportParametersString = value;
     _reportParameters.Clear();
     if (string.IsNullOrEmpty(_reportParametersString)) return;

     // parse the report parameters
     flag = "parse_parms";
     string[] parms = _reportParametersString.Split(';');
     if (parms.Length == 0) return;

     // parse each parameter
     flag = "iter_parms";
     foreach (string parm in parms)
     {
      // sanity
      if (string.IsNullOrEmpty(parm)) continue;

      // validate
      int idxEqual = parm.IndexOf('=');
      if (idxEqual <= 0)
      {
       throw new ApplicationException(
        string.Format("Parameter {0} should be in format Name=Value", parm)
       );
      } //if

      // construct the parm
      string parmName = parm.Substring(0, idxEqual);
      string parmValue = parm.Substring(idxEqual + 1);
      Telerik.Reporting.ReportParameter reportParm = new Telerik.Reporting.ReportParameter(
       parmName, Telerik.Reporting.ReportParameterType.String, parmValue
      );
      _reportParameters.Add(reportParm);
     } //foreach

     // if we have already loaded the page,
    }
    catch (Exception ex)
    {
     LH.error("Problem at ", flag, ": ", ex);
     NotifyError("Report Problem: " + ex.Message);
    } //try
   } //set
  } //ParametersString

  /// <summary>
  /// Handle export status
  /// </summary>
  /// <param name="e"></param>
  protected override void OnInit(EventArgs e)
  {
   // create controls
   base.OnInit(e);
  }

  /// <summary>
  /// Auto-generated
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  protected void Page_Load(object sender, EventArgs e)
  {
   // indicate Page_Load has fired
   _pageIsLoaded = true;

   // check to see if we need to do a one-time load
   if (IsFirstTime)
   {
    if (Report != null)
    {
     // user set report explicitly; use that
     setReport();
    }
    else if (!string.IsNullOrEmpty(ReportName))
    {
     // report name set via ASCX; use that
     loadReport();
    } //if

    // only do this once
    SetFirstTime(false);
   } //if

   // set the height every time from hidden variable
   try
   {
    Unit unitExplicitHeight = Unit.Parse(hdnExplicitHeight.Value);
    if (unitExplicitHeight != Unit.Empty && unitExplicitHeight.Value > 0)
    {
     // safety
     if (unitExplicitHeight.Value < 100)
     {
      unitExplicitHeight = Unit.Parse("100px");
     } //if
     Height = unitExplicitHeight;
    } //if
   }
   catch
   {
   } //try
  }

  /// <summary>
  /// Put in our own control height (page height)
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  protected void rptvw_Init(object sender, EventArgs e)
  {
   string flag = "";
   try
   {
    // find the toolbar
    flag = "locate_toolbar";
    Control ctlToolbar = rptvw.FindControl("ReportToolbar");
    if (ctlToolbar == null) throw new ApplicationException("No toolbar; new Telerik version?");

    // this is reverse engineered from telerik; might work
    flag = "create_controls";
    Table tblHeight = new Table();
    tblHeight.ID = "PageHeight";
    tblHeight.CssClass = "ReportToolbarGroup";
    Abr.CodeLibrary.Utils.Global.MergeCssStyleAttributes(tblHeight.Attributes, "float:left;");
    tblHeight.CellPadding = 0;
    tblHeight.CellSpacing = 0;

    TableRow rowHeight = new TableRow();
    rowHeight.ID = "row";

    TableCell cellHeight = new TableCell();
    cellHeight.ID = "cell";

    Label lblHeight = new Label();
    lblHeight.ID = "lblHeight";
    lblHeight.AssociatedControlID = "txtHeight";
    lblHeight.Text = "Height: ";

    _txtHeight = new TextBox();
    _txtHeight.ID = "txtHeight";
    _txtHeight.Width = Unit.Parse("5em");

    LinkButton btnResize = new LinkButton();
    btnResize.ID = "btnResize";
    btnResize.Text = "Resize";
    btnResize.Click += new EventHandler(btnResize_Click);

    flag = "add_controls";
    cellHeight.Controls.Add(lblHeight);
    cellHeight.Controls.Add(_txtHeight);
    cellHeight.Controls.Add(btnResize);
    rowHeight.Cells.Add(cellHeight);
    tblHeight.Rows.Add(rowHeight);
    ctlToolbar.Controls.Add(tblHeight);
   }
   catch (Exception ex)
   {
    LH.error("Problem at ", flag, ": ", ex);
    NotifyError("Report: " + ex.Message);
   } //try
  }

  /// <summary>
  /// Used to capture explicit resize
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  void btnResize_Click(object sender, EventArgs e)
  {
   hdnExplicitHeight.Value = _txtHeight.Text;
   Height = Unit.Parse(_txtHeight.Text);
  }
 } //TelerikReportViewer
} //namespace

 

 

 

 

 

 

shahzad
Top achievements
Rank 1
 answered on 29 Dec 2011
1 answer
123 views
Hi.
I'm having problem using the report guide because i can not find referenced EF (it's in another project).
I have two project, one with my EF data model, and another project with my reports.
I have made a reference of the EF project into my report project, byt when i run the report wizard, i can not add/find my model.
So how can this be done? How can i have separate project for my EF model and for my reports?

BR
Linus
Peter
Telerik team
 answered on 29 Dec 2011
0 answers
91 views
We have some telerik forms created in our application that you can display and then print on demand. The issue is the forms render  based on the default printer installed on the computer. For example, I have a generic HP printer attached to my computer, and the form displays correctly before printing. A co worker has a bar code printer installed as their default printer, and when they view the form, it breaks up the one page form to display in bar code sized windows. How do we change this so the intial display is a regular 8 1/2 x 11 display or PDF, regardless of printer installed? This form needs to be displayed in a proper manner on all client machines, but does not require printing on all machines.
Thanks
Ken
Top achievements
Rank 1
 asked on 28 Dec 2011
2 answers
92 views
When I get a server error in my silverlight viewer, I only see a blank in the report viewer.  On the asp.net report viewer I see the error just fine.  I'll get an out of memory error a lot, and I want to be able to see that, or pop up a rad window saying there was an out of memory error, please filter your data.  I don't see any events where I can catch the message.

Our clients want to print out 1000-5000 page reports, but my test server doesn't have much memory on it, so I expect to get a lot of errors during testing.
danparker276
Top achievements
Rank 2
 answered on 28 Dec 2011
3 answers
212 views
Hi Telerik team.

I have a problem whit my Page Header Section Report. It simple, print preview not match with report view. Details about the design and views of the report are the images attached.

Can you help us with is issue.
Giuliano Caetano.
Elian
Telerik team
 answered on 28 Dec 2011
2 answers
114 views
Is it possible to share the source code of the Invoice Report given in the Reporting Demos?
Emre
Top achievements
Rank 1
 answered on 28 Dec 2011
2 answers
106 views
Hi there,

I follow this tutorial: http://tv.telerik.com/watch/reporting/video/getting-started-with-telerik-report-viewer-silverlight but I can´t display my report in ReportViewer: Give me that error, see in attache please.

To help you, here are my webConfig:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="PathReunioes" value="Reunioes" />
    <!--<add key="PathReunioes" value="\\192.168.10.20\usa_esta" />-->
    <add key="PathTemporarios" value="Temp" />
    <add key="PathUpload" value="Upload" />
    <add key="PathExtras" value="Extras" />
    <add key="gravacaoAnexosBD" value="N" />
    <add key="gravacaoDocumentosReuniaoBD" value="N" />
    <add key="logotipo1" value="/Extras/logotipo1.png" />
    <add key="logotipo1_X" value="100" />
    <add key="logotipo1_Y" value="100" />
    <add key="logotipo1_Largura" value="200" />
    <add key="logotipo1_Altura" value="100" />
    <add key="logotipo2" value="/Extras/logotipo2.png" />
    <add key="logotipo2_X" value="100" />
    <add key="logotipo2_Y" value="100" />
    <add key="logotipo2_Largura" value="200" />
    <add key="logotipo2_Altura" value="100" />
    <add key="numeroMaximoAnexosSessaoUpload" value="6" />
    <add key="numeroMaximoDocumentosReuniaoSessaoUpload" value="4" />
    <add key="id_TipoEntidade_Sistema" value="4" />
    <add key="numeroMaximoChamadas" value="3" />
    <add key="caminhoExecutavelOpenOffice" value="C:\Program Files (x86)\OpenOffice.org 3\program\soffice.exe" />
    <add key="timeoutOpenOffice" value="1000" />
    <add key="cache" value="N" />
  </appSettings>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </modules>
  </system.webServer>
  <system.web>
    <httpRuntime maxRequestLength="10000000" executionTimeout="3600" />
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>
    <compilation debug="true" targetFramework="4.0" />
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
  <connectionStrings>
    <add name="ConexaoBDSGA" connectionString="data source=bd01;password=sga_demo123;persist security info=True;user id=SGA_DEMO" providerName="Oracle.DataAccess.Client" />
  </connectionStrings>
  <system.serviceModel>
    
    
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="ReportServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="WebBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    <services>
      <service
              name="Telerik.Reporting.Service.ReportService"
              behaviorConfiguration="ReportServiceBehavior">
        <endpoint
               address=""
               binding="basicHttpBinding"
               contract="Telerik.Reporting.Service.IReportService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint
                address="resources"
                binding="webHttpBinding"
                behaviorConfiguration="WebBehavior"
                contract="Telerik.Reporting.Service.IResourceService"/>
        <endpoint
                address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
      </service>
    </services>

  </system.serviceModel>
</configuration>

My XAML:

<navigation:Page x:Class="SGA.Views.SGASeguranca"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:UC="clr-namespace:SGA.UserControls"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           xmlns:telerik="clr-namespace:Telerik.ReportViewer.Silverlight;assembly=Telerik.ReportViewer.Silverlight"
           Title="SGA - Segurança" Unloaded="Page_Unloaded">
    <Grid x:Name="LayoutRoot">
        <telerik:ReportViewer  x:Name="ReportViewer1" Width="1000"
                              >
        </telerik:ReportViewer>
    </Grid>
</navigation:Page>

And my Code-Behind:

using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows;

namespace SGA.Views
{
    public partial class SGASeguranca : Page
    {
        public SGASeguranca()
        {
            InitializeComponent();

            try
            {
                ReportViewer1.Report = "Telerik.Reporting.Service.ReportService, Telerik.Reporting.Service, Version=5.3.11.1116, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE";
                ReportViewer1.ReportServiceUri = new Uri("../ReportService.svc",UriKind.RelativeOrAbsolute);
            }
            catch(Exception e)
            {
            }

        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = null;
            GC.Collect();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
        }
    }    

}

Thanks in advance.


IvanY
Telerik team
 answered on 28 Dec 2011
4 answers
107 views
I've just upgraded to Q3 2011 from Q2 2011..

After upgrade, every report that have picturebox in a table cell will return this error

The given key was not present in the dictionary.

[KeyNotFoundException: The given key was not present in the dictionary.]
   System.Collections.Generic.Dictionary`2.get_Item(TKey key) +9627953
   Telerik.Reporting.Processing.Imaging.ImageInfoCache.GetInfo(String key) +13
   Telerik.Reporting.Processing.PictureBox.get_ImageInfo() +60
   Telerik.Reporting.Paging.PictureBox.get_ImageInfo() +44
   Telerik.Reporting.Paging.PictureBox.InitPageInfo(ElementPageInfo pageInfo, RectangleRF clip) +98
   Telerik.Reporting.Paging.RenderingElementBase.AddToPageRecursive(RectangleRF parentClip, Double parentTop, Double parentLeft, Double parentReservedTop, Double parentReservedBottom, Double parentReservedLeft, Double parentReservedRight) +457
   Telerik.Reporting.Paging.Table.RenderCell(ITableCell cell, RectangleRF clip, Double left, Double top, Double reservedLeft, Double reservedTop) +110
   Telerik.Reporting.Paging.Table.RenderCell(ITableCell cell, RectangleRF clip, Double left, Double top, Double reservedLeft, Double reservedTop, List`1 renderedCellList) +141
   Telerik.Reporting.Paging.Table.RenderCells(TableRegion region, RectangleRF clip, Double left, Double top, Double reservedLeft, Double reservedTop) +167
   Telerik.Reporting.Paging.Table.AddChildrenToPage(RectangleRF clip) +470
If I delete the column with the picturebox in it, the reports works fine.

FYI, this problem occurred only for reports containing picturebox in a table cell, whether or not the value is set.  If its not in any table cell, it works fine.

Jari
Top achievements
Rank 1
 answered on 28 Dec 2011
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?