How to add and bind data source to parameter programmatically

3 posts, 0 answers
  1. 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
    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
  2. Peter
    Peter avatar
    1611 posts

    Posted 27 May 2011 Link to this post

    Hi Anoop,

    Do you want use the data from the Report Parameters as datasource? If this is the case you should know that the allowed report parameter types are Boolean, DateTime, Integer, Float, String and for other types you can use a public property of the report that will simplify things:

    class Report1 : Telerik.Reporting.Report
        public System.Drawing.Image Logo
            get{ ... }
            set{ ... }

    If you want to use a report parameter value as a report item(Textbox) value then you can use the following expression:
    textBox1.Value = "= Parameters.Parameter1.Value";

    About the ObjectDataSource component - check the ObjectDataSource help articles. In the concrete case from the provided code snippet Cars is type that inherits List<Cars> and returns a list of Cars objects. Check out the DataBinding demo that came with your installation of Telerik Reporting start -> All Programs -> Telerik -> Reporting Q1 2011 -> Visual Studio 2010 Examples.

    If you want to create your reports programmatically we highly recommend creating the desired table/group/column through the Report Designer first and then review the code in the InitializeComponent to see the internal structure.

    Let us know how it goes and if you need additional assistance we will appreciate if you elaborate further on you scenario.

    Best wishes,
    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
  3. DevCraft R3 2016 release webinar banner
  4. Anoop
    Anoop avatar
    76 posts
    Member since:
    Sep 2006

    Posted 29 May 2011 Link to this post

    Thanks a lot  Peter for your reply,,

    I want the parameter as Drop Down Menu.

Back to Top