This is a migrated thread and some comments may be shown as answers.

How to add and bind data source to parameter programmatically

2 Answers 591 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anoop
Top achievements
Rank 1
Anoop asked on 25 May 2011, 11:42 AM

Hi,,..

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

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 27 May 2011, 12:04 PM
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,
Peter
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
0
Anoop
Top achievements
Rank 1
answered on 29 May 2011, 07:45 AM
Thanks a lot  Peter for your reply,,

I want the parameter as Drop Down Menu.

Tags
General Discussions
Asked by
Anoop
Top achievements
Rank 1
Answers by
Peter
Telerik team
Anoop
Top achievements
Rank 1
Share this question
or