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

Passing parameters to report via webform with reporterviewer and dropdown

3 Answers 239 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SMA SOFTWARE
Top achievements
Rank 1
SMA SOFTWARE asked on 10 Feb 2010, 10:44 PM
Hi,

I really need to find a step by step solution to make this work, I swear I tried all the indications and videos posted here, I searched the forum and looked at all the threads.

I can not resolve the passage of bind parameters to the report,

My report uses a dataset with a SqlTableAdapter, and when I set the value of the parameter by hand, inside the "reportParametes" and "filters" thats works fine.

but now, I need to call that report from a ReportViewer in a aspx webform, i also need to pass the value selected in a DropDown to filter the Report Results.

I'm using the newest version of TelerikReporting, but the videos and Howtos that I've found here seen to be for old version.

please, anyone could give a light?  a "step by step" how to get that thing working

Scenario:
  • A Webform  reportview.aspx with DropDown with years ( 2008/2009/2010) and a ReporterViewer that calls report1 class from my referenced assembly.
  • My report class is running well from "Preview" when I set the parameters by hand, but I need to get that parameter from reportviewer aspx page
  • I'm using a Dataset with SqlTableAdapter where the method GetDataBy(@year) needs a parameter with the selected Year, to execute SELECT * FROM MYTABLE WHERE YEAR(DATE) = @year

What I have to do , to pass the Year selected in DropDown to the report called by the ReporterViewer?

Tks






3 Answers, 1 is accepted

Sort by
0
SMA SOFTWARE
Top achievements
Rank 1
answered on 11 Feb 2010, 03:13 PM
Some example to help you helping me!

In Report1 I have a Table called table1 , this table have no DataSource defined

I need to populate the table so i Tried.

to define the NeedDataSource to the table.

 public partial class Report1 : Telerik.Reporting.Report 
    { 
 
        public string Login; 
 
        public Report1() 
        { 
             
            InitializeComponent(); 
             
            
            this.table1.NeedDataSource += new EventHandler(table1_NeedDataSource); 
        } 
 

the event handler

  void table1_NeedDataSource(object sender, EventArgs e) 
        { 
            this.table1.DataSource = GetData(Login); 
             
        } 

The method that returns the DataSource

  private DataTable GetData(string Login) 
        { 
 
            SqlConnection sqlconn1 = new SqlConnection(); 
            SqlCommand sqlcomm1 = new SqlCommand(); 
            SqlDataAdapter sqldata1 = new SqlDataAdapter(); 
            DataTable table = new DataTable(); 
             
            sqlconn1.ConnectionString = Properties.Settings.Default.coelbareport; 
 
            sqlcomm1.CommandType = CommandType.Text; 
            sqlcomm1.CommandText = "SELECT     SicaiHistoricoPesquisaSalva.* FROM  SicaiHistoricoPesquisaSalva where login = @login"
            sqlcomm1.Parameters.Add(new SqlParameter("login",Login)); 
            sqlcomm1.Connection = sqlconn1; 
            sqldata1.SelectCommand = sqlcomm1; 
 
            sqldata1.Fill(table); 
 
            return table; 
 
 
             
            
             
 
        } 


If I set the Login property by hand ( hardcoded), everything runs ok!

Now I need to present that Report within a ReportViewer in aspx

I created an aspx webform

telerik:ReportViewer ID="ReportViewer1" runat="server"
        </telerik:ReportViewer> 

in The code behind I tried.

  protected void Page_Load(object sender, EventArgs e) 
    { 
        ReportViewer1.Report = new Report1(); 
        (ReportViewer1.Report as Report1).Login = "bcrocha"
        ReportViewer1.RefreshReport(); 
         
    } 

OK, Debugging I found that my parameter "bcrocha" string is rightly set to the "Login" property

but nothing happens..

My Report loads with the table1 empty :(

what's wrong?

Regards

Screenshot attached,
0
Accepted
Peter
Telerik team
answered on 15 Feb 2010, 10:26 AM
Hi SMA SOFTWARE,

Please review the Adding a Data Source through NeedDataSource report event help article. The problem is that you had used the table's definition item instead of its processing counterpart (Telerik.Reporting.Processing.Table) i.e.:

void table1_NeedDataSource(object sender, EventArgs e)
      {
          (sender as Telerik.Reporting.Processing.Table).DataSource = GetData(Login);
            
      }

Check out the help article Understanding Events for better understanding of the above.

All the best,
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
SMA SOFTWARE
Top achievements
Rank 1
answered on 19 Feb 2010, 06:01 PM
Thank you! that works great!

Bruno - SMA
Tags
General Discussions
Asked by
SMA SOFTWARE
Top achievements
Rank 1
Answers by
SMA SOFTWARE
Top achievements
Rank 1
Peter
Telerik team
Share this question
or