I have a report which has some table controls on it. This report also has embedded subreports on it. I have the requirement of taking some info about the user(username) from my web app and passing it as a parameter to my telerik report. I have watched the video for paramterized queries (here) and am trying to model after this. It works....only sort of...
What is weird is that the parameters are passed just fine to my subreports . I use the NeedDataSource Event to do so. For some reason, when I try to pass the parameters to the queries (I am calling stored procs) that populate the table controls(again these controls are directly on the report), these values get lost somehow. Very weird, as I would think the the exact opposite would potentially be the case.
I turned sql profiler on and I can see the queries running for the table controls with a blank string " " for the parameters that are suppose to be passed. Even weirder is if I make the paramers visible in the automatic UI, (while making absolutely certain that no value has been hardcoded for them in the properties window of Visual Studio, Value field is blank) I do in fact see the values in the automatic UI that are supposed to be passed to the report. I tried using the different events(NeedDataSource, ItemDataBound, etc) to bind the table controls but to no avail.
Based on what I'm experiencing I would think there is something about the report life cycle that I am currently not understanding, but I am not sure. Below are my code snippets with comments. If you can offer any direction I would be greatly appreciative. -Jason
What is weird is that the parameters are passed just fine to my subreports . I use the NeedDataSource Event to do so. For some reason, when I try to pass the parameters to the queries (I am calling stored procs) that populate the table controls(again these controls are directly on the report), these values get lost somehow. Very weird, as I would think the the exact opposite would potentially be the case.
I turned sql profiler on and I can see the queries running for the table controls with a blank string " " for the parameters that are suppose to be passed. Even weirder is if I make the paramers visible in the automatic UI, (while making absolutely certain that no value has been hardcoded for them in the properties window of Visual Studio, Value field is blank) I do in fact see the values in the automatic UI that are supposed to be passed to the report. I tried using the different events(NeedDataSource, ItemDataBound, etc) to bind the table controls but to no avail.
Based on what I'm experiencing I would think there is something about the report life cycle that I am currently not understanding, but I am not sure. Below are my code snippets with comments. If you can offer any direction I would be greatly appreciative. -Jason
//this from my .aspx codebehind |
public partial class reporting_rep_invprodby_newlook2 : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
string username = User.Identity.Name; |
MasterReport report1 = new MasterReport(); |
ReportViewer1.Report = report1; |
//setting the value of Param1 in the line below |
report1.Param1 = username; |
} |
------------------------------------------------------------------------------ |
//this from the telerik report codebehind |
// Here is a sample query where the value for @ousername_vc |
//(this.ReportParameters["ousername_vc"].Value) gets lost |
SqlConnection connSomsys = new SqlConnection(@"Server=cmdivst004\Jason08;Integrated Security=false;Database=QuoteDB; Persist Security Info=True;User ID=gggg;Password=gggg"); |
SqlCommand selectLastYearTot; |
selectLastYearTot = new SqlCommand("sprocgetOrdertotlastyear", connSomsys); |
selectLastYearTot.CommandType = CommandType.StoredProcedure; |
selectLastYearTot.Parameters.AddWithValue("@ousername_vc", this.ReportParameters["ousername_vc"].Value); |
adapter3.Fill(dataSet3); |
this.table3.DataSource = dataSet3; |
//this is for one of the subreports in the NeedDataSource Event |
//for the subreport, it works fine |
SqlConnection connSomsys = new SqlConnection(@"Server=cmdivst004\Jason08;Integrated Security=false;Database=QuoteDB; Persist Security Info=True;User ID=cmdiapp;Password=adiadmin"); |
Telerik.Reporting.Processing.SubReport report =(Telerik.Reporting.Processing.SubReport)sender; |
SqlCommand selectCommand; |
selectCommand = new SqlCommand("sprocgetaccountingorders", connSomsys); |
selectCommand.CommandType = CommandType.StoredProcedure; |
//works fine right here line below |
selectCommand.Parameters.AddWithValue("@ousername_vc", this.ReportParameters["ousername_vc"].Value); |
SqlDataAdapter adapter = new SqlDataAdapter(selectCommand); |
DataSet dataSet = new DataSet(); |
adapter.Fill(dataSet); |
report.InnerReport.DataSource = dataSet; |
connSomsys.Dispose(); |
//Here is the property I created to take in the value of the username |
//much like the video |
public string Param1 |
{ |
get |
{ |
return (string)this.ReportParameters["ousername_vc"].Value; |
} |
set |
{ |
this.ReportParameters["ousername_vc"].Value = value; |
} |
} |