Change textbox on report in LocalMode via code? RRS feed

  • Question

  • In VS2008, I have a ReportViewer control displaying a report on an .aspx page. The report's datasource is an ObjectDataSource on the .aspx page. My report has no parameters (on the .rdlc file itself), but the ODS has some.  When the user selects the report options, I set all of the SelectParameter's DefaultValue properties and then simply do a myReport.LocalReport.Refresh(); This works as desired and allows me to display a wide variety of reports with 1 .aspx page, just changing the ReportViewer's ReportPath property to point to a different .rdlc file.

    My question is:  how can I programmatically set the value of a TextBox on the .rdlc file to display the report options that the user chose? 

    My code currently looks like this:

            protected void OnbtnViewClick(object sender, EventArgs e)  
                rvReport.LocalReport.ReportPath = ddlReport.SelectedValue;  
                odsReport.SelectParameters["pParm1"].DefaultValue = ddlDropdown1.SelectedValue;  
                //Why won't this work to set value on .rdlc to show parm option?  
                TextBox txtParm1 = (TextBox)rvReport.FindControl("txtParm1");  
                txtParm1.Text = ddlDropdown1.SelectedItem.Text;  

    Any ideas on how I can set the value of txtParm1 (a textbox on my .rdlc file) to the value of a DropDownList on my .aspx page?

    Monday, August 4, 2008 4:56 PM


  • Report items are not webform level controls and are not known to ASP.Net, so they aren't accessible via the FindControl API.  If you want to populate the value of a textbox in a report programmatically, you can create another parameter on your report.  Set the value of the parameter to the text you want displayed and set the display value of the textbox to the value of the new parameter.
    • Proposed as answer by Long Xue Wednesday, August 13, 2008 8:53 PM
    • Marked as answer by lunchroom Friday, March 27, 2009 7:14 PM
    Tuesday, August 5, 2008 6:14 AM