Build a report programmatically

8 posts, 0 answers
  1. Anoop
    Anoop avatar
    76 posts
    Member since:
    Sep 2006

    Posted 09 May 2011 Link to this post

    Hi,

    I am trying to build a report programmatically without using the wizard. In this report am using parameter which also should be done programmatically according to my data, and through a query that also be added.

     

    I tried this >> http://www.telerik.com/help/reporting/programmatic-creating-report.html

     

    But I don’t know why am getting and empty report?!

     

    Also the parameters and filter?!

     

    Is there is any procedures behind that


    this is a part of what i did, i might be missing something,, lemme know please?
    Thanks in advance

    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Telerik.Reporting
    Imports Telerik.Reporting.Drawing
    Imports System.Data.SqlClient
      
    Partial Public Class Visitreport
        Inherits Telerik.Reporting.Report
        Public Sub New()
            InitializeComponent()
            Dim report As New Report()
            'Dim sql As String = "SELECT  "
            Dim sql As String = ""
            Dim connectionString As String = ""
            Dim adapter As New SqlDataAdapter(sql, connectionString)
            report.DataSource = adapter
            'creating item programatically 
            Dim detail As New DetailSection()
            Me.detail.Height = New Telerik.Reporting.Drawing.Unit(3, Telerik.Reporting.Drawing.UnitType.Inch)
            Me.detail.Name = "detail"
            report.Items.Add(DirectCast(detail, ReportItemBase))
      
            Dim panel1 As New Telerik.Reporting.Panel()
            Dim textBox1 As New Telerik.Reporting.TextBox()
      
            'panel1
      
      
            panel1.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Cm))
            panel1.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(8.5, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(3.5, Telerik.Reporting.Drawing.UnitType.Cm))
            panel1.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid
      
            'textBox1
      
      
            textBox1.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm))
            textBox1.Name = "NameDataTextBox"
            textBox1.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(5, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(0.6, Telerik.Reporting.Drawing.UnitType.Cm))
            textBox1.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid
            textBox1.StyleName = "Data"
            textBox1.Value = "=Fields.AssignTo"
      
            panel1.Items.AddRange(New Telerik.Reporting.ReportItemBase() {textBox1})
            detail.Items.AddRange(New Telerik.Reporting.ReportItemBase() {panel1})
      
            Dim reportParameter1 As New Telerik.Reporting.ReportParameter()
            reportParameter1.Name = "Parameter1"
            reportParameter1.Text = "Enter Value for Parameter1"
            reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer
            reportParameter1.AllowBlank = False
            reportParameter1.AllowNull = False
            reportParameter1.Value = "=10"
            reportParameter1.Visible = True
            report.ReportParameters.Add(reportParameter1)
            reportParameter1.AvailableValues.DataSource = adapter
            reportParameter1.AvailableValues.ValueMember = "= Fields.AssignTo"
            reportParameter1.AvailableValues.DisplayMember = "= Fields.AssignTo"
            Dim filter1 As New Telerik.Reporting.Data.Filter()
            filter1.Expression = "=Fields.AssignTo"
            filter1.Operator = Telerik.Reporting.Data.FilterOperator.Equal
            filter1.Value = "=Parameters.AssignTo"
            reportParameter1.AvailableValues.Filters.AddRange(New Telerik.Reporting.Data.Filter() {filter1})
            Dim sorting1 As New Telerik.Reporting.Data.Sorting()
            sorting1.Expression = "=Fields.AssignTo"
            sorting1.Direction = Telerik.Reporting.Data.SortDirection.Asc
            reportParameter1.AvailableValues.Sortings.AddRange(New Telerik.Reporting.Data.Sorting() {sorting1})
      
      
            '   report.ReportParameters("AssignTo").Value = ""
      
        End Sub
      
        Private Sub detail_ItemDataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles detail.ItemDataBound
            'Take the Telerik.Reporting.Processing.Report instance
            'Dim report As Telerik.Reporting.Processing.Report = DirectCast(sender, Telerik.Reporting.Processing.Report)
      
            ' Transfer the value of the processing instance of ReportParameter
            ' to the parameter value of the sqlDataSource component
            '   Me.SqlDataSource1.Parameters(0).Value = report.Parameters("AssignTo").Value
      
            ' Set the SqlDataSource component as it's DataSource
            report.DataSource = Me.SqlDataSource1
      
        End Sub
    End Class
  2. Anoop
    Anoop avatar
    76 posts
    Member since:
    Sep 2006

    Posted 10 May 2011 Link to this post

    the above code should be in the report or in the loadform??
  3. DevCraft banner
  4. veena
    veena avatar
    9 posts
    Member since:
    Feb 2011

    Posted 10 May 2011 Link to this post

    Hi Anoop,

    I have added a post to create report dynamically based on datasource. The only problem I face is Reportheader where I place column heading, is not on all pages. I wish instead of dynamically creating columns I could load them into table. Have a look, if you can do it please add your solution to the post

    http://www.telerik.com/community/forums/reporting/telerik-reporting/fully-dynamic-report.aspx
  5. Hrisi
    Admin
    Hrisi avatar
    221 posts

    Posted 12 May 2011 Link to this post

    Hello Anoop,

    If you want to build the report programmatically, you should be familiar with the Report definition object model. The best guide for this is the code generated in [YourReport].Designer.vb by using the Report Designer in Visual Studio.

    From your code in the constructor you should remove this line:
        Dim report As New Report()
    and instead of using the local report variable, consider using the Me.

    Best wishes,
    Hrisi
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Anoop
    Anoop avatar
    76 posts
    Member since:
    Sep 2006

    Posted 25 May 2011 Link to this post

    I had added a parameter, however am not able to build the datasourse object

     

    I do not want to use the sqldatasourse control, so how can I build it to get the data from the parameter I create.

    How to bind the data to it

     

    I use this code to build the parameter



    Dim reportParameter1 As New Telerik.Reporting.ReportParameter()
            reportParameter1.Name = "Parameter1"
            reportParameter1.Text = "Category"
            reportParameter1.Type = Telerik.Reporting.ReportParameterType.String
            reportParameter1.AllowBlank = False
            reportParameter1.AllowNull = False
            reportParameter1.Value = "= Fields.Category"
            reportParameter1.Visible = True
            Report.ReportParameters.Add(reportParameter1)
      
    reportParameter1.AvailableValues.DataSource = objectDataSource1
            reportParameter1.AvailableValues.ValueMember = "= Fields.Category"
            reportParameter1.AvailableValues.DisplayMember = "= Fields.Category"

    Furthermore, I wanna bind this parameter to a objectdatasourse,,so I found this code but I could not use it


    Public Sub HowToObjectDataSourceParameters()
        Dim objectDataSource1 As New Telerik.Reporting.ObjectDataSource()
        objectDataSource1.DataMember = "GetCars"
        objectDataSource1.DataSource = GetType(Cars)
        objectDataSource1.Parameters.Add(New Telerik.Reporting.ObjectDataSourceParameter("year", GetType(Integer), 2010))
        objectDataSource1.Parameters.Add(New Telerik.Reporting.ObjectDataSourceParameter("color", GetType(String), "=Parameters.Color"))
    End Sub

    objectDataSource1.DataSource = GetType(Cars)<>>>> what is Cars? <<>>what do they mean by this type,, i did not get it.

    Thanks in advance
  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 May 2011 Link to this post

    Hi Anoop,

    We see that you want to wire up the DataSourceParameter with a ReportParameter. It does not matter whether you're using SqlDataSource or ObjectDataSource Component. The code you've found in the Using Parameters with the ObjectDataSource Component help article is correct and is "using" the Cars class from the ListBound report example. You can open the demo reports locally and review the implementation.

    Best wishes,
    Steve
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Anoop
    Anoop avatar
    76 posts
    Member since:
    Sep 2006

    Posted 29 May 2011 Link to this post

    Hi Steve,

    Thanks a lot for your reply

    What I need is sqlDatasource to retrieve the info of the parameter from the database,..

     

    I tried the suggested code but it did not give me any intended result.

    Where exactly should I place this codes?,, is there is any event for this to be run

     

    See the report1 attached picture that what I get only the parameter is added without any data..

     

    In report2 attached picture I used the Dynamic way to get the data >>that what I want using the code but I could not reach to it

     

     

    Thanks a lot in advance

  9. veena
    veena avatar
    9 posts
    Member since:
    Feb 2011

    Posted 29 May 2011 Link to this post

    Anoop,

    The way I used object datasource while using EF, by creating a function in class which fetches data from SQL server(in our case it was EDM). You must be using dataobject project or class in your solution, reference that class in the project where you have added reports. Add object datasouce and you should be able to navigate to the class and function, later add the parameters used in the function.
Back to Top
DevCraft banner