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

Get report parameters in report viewer

5 Answers 498 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Naphtali
Top achievements
Rank 1
Naphtali asked on 20 Jul 2009, 10:57 AM

Hi,

I have created a report with the built in UI. I create the parameters programmatically in the following way:

 

ReportParameter

 

parameter = new ReportParameter();

 

parameter.Name =

"ParameterOne";

 

parameter.UI.AvailableValues.DataSource = m_dataSource;

parameter.UI.AvailableValues.DisplayMember =

"displayText";

 

parameter.UI.AvailableValues.ValueMember =

"value";

 

parameter.UI.Visible =

true;

 

parameter.UI.Text =

"please choose a value";

 

parameter.Value =

"None";

 

report.ReportParameters.Add(parameter);

 

In addition to the report i have a aspx page with a web report viewer and a button.
In the button event click I would like to read the values of the parameters as the user entered (or the default values if none were entered) and save them to my database.

I can't get to the new values, all I get is the default values.

I think if I could fire the Need_DataSource event I would be able to read the values the users chose there. But I can't figure out a way to fire the event without creating a new report and then loosing all the information I need.

Is this they way to get what I want? If so how can I fire the event. If not how can I achieve what I want?

Naphtali

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 20 Jul 2009, 12:37 PM
Hi naphtali,

You can get the values easily like this:

  Telerik.Reporting.Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;
  string paramvalue = report.ReportParameters["MyParam"].Value.ToString();

Regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Naphtali
Top achievements
Rank 1
answered on 23 Jul 2009, 11:05 AM
Hi,
Thanks for your reply.
It isn't working. When I press my save button the ReportViewer1.Report is null.

I need to mention that I cann't do the following in the page load event:

ReportViewer1.Report =

new Report()
since the constructor of the reports creates the paramters and sets the default values, so I wont get the users selection. The constructor is the only place I could get the parameters to work.

Naphtali

 

0
Steve
Telerik team
answered on 23 Jul 2009, 11:35 AM
Hello naphtali davies,

I'm not sure I understand your dilemma and why it would not work. It makes no difference whether you have created the report parameters through the report designer or manually in the report constructor - it's all the same. Generally speaking the proper place to do this is NeedDataSource event of the report, which as explained in the documentation, would be fired only when there is no datasource set to the report i.e. you would have to bind your report in the NeedDataSource event as well e.g.:

private void MyReport_NeedDataSource(object sender, System.EventArgs e)         
{         
  //Get the ReportParameter value         
  string paramvalue = this.ReportParameters["ManagerID"].Value;         
         
  //Take the Telerik.Reporting.Processing.Report instance and set       
  //it's DataSource         
  Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;         
  report.DataSource = <your_datasource>;         


Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Naphtali
Top achievements
Rank 1
answered on 23 Jul 2009, 11:57 AM
This is code form my report:

 

 

 

public MyReport()

 

{

 

/// <summary>

 

 

 

 

 

 

/// Required for telerik Reporting designer support

 

 

 

 

 

 

/// </summary>

 

 

 

 

 

InitializeComponent();

CreateReportParameters();

 

///This is done in order that the NeedDataSource event will rise.

 

 

 

 

 

DataSource =

null;

 

}

 

/// <summary>

 

 

 

 

 

 

/// The first event the rises. Here we read the parameters and build the report accordingly.

 

 

 

 

 

 

/// </summary>

 

 

 

 

 

 

/// <param name="sender"></param>

 

 

 

 

 

 

/// <param name="e"></param>

 

 

 

 

 

 

private void MyReport_NeedDataSource(object sender, EventArgs e)

 

{

 

ReportBuilder reportBuilder = new ReportBuilder();

 

reportBuilder.ClearReport();

reportBuilder.BuildReport();

m_dataSource = GetDataSource();

(sender

as Telerik.Reporting.Processing.Report).DataSource = m_dataSource;

 

}

In my aspx file I have the following code:

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

if (!IsPostBack)

 

{

ReportViewer1.Report =

new MyReport();

 

}

}

 

protected void SaveButton_Click(object sender, EventArgs e)

 

{

Telerik.Reporting.

Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;

 

 

var parameters = report.ReportParameters;

 

 

foreach (var param in parameters)

 

{

 

//save them to database

 

 

 

 

 

}

}

In the SaveButton_Click the this.ReportViewer1.Report is null.

So How can I get the values the user entered in the browser back to me in the SaveButton_Click?

0
Naphtali
Top achievements
Rank 1
answered on 28 Jul 2009, 10:32 AM
Can someone please help me with this?
Tags
General Discussions
Asked by
Naphtali
Top achievements
Rank 1
Answers by
Steve
Telerik team
Naphtali
Top achievements
Rank 1
Share this question
or