Use a variable as a text value of a textbox in a report viewer
How to use a variable as a text value of a textbox in a report viewer?
Example
dim sExamDate as string = "09/07/2007"
What will i do to make "09/07/2007" be displayed in my report viewer?
I will add a page header like this "Exam Date from 05/01/2007 to 09/07/2007" to my report.
Answers
WalangAlam,
Please add page header in your ReportViewer as the following steps:
1. Open a client report definition (.rdlc) file in graphical design mode.
2. On the Report menu, click Page Header. Page Header is toggle items on the Report menu. When enabled, a Page Header or Page Footer section appears on the design surface.
3. Alternatively, right-click in the empty area outside of the design surface, and then click Page Header.
Drag any of the following items from the Toolbox to the Page Header or Page Footer area: Textbox, Line, Rectangle,Image
4. Set properties on the Page Header or Page Footer to add borders, background images or colors, adjust width, or suppress headers or footers on the first page. To set these properties, right-click the Page Header or Page Footer area and select Properties.
The you can set the text in the controls on ReportViewer header according to your demand.
Hope that can help you.
Insert a Textbox in your report and set the value of the textbox to the parameter. In the Win form,
First you need to import Windows.Reporting.Winform
On button click event,
-------------------------------------------------------------------------------------------------------------
Dim Param(0) as ReportParameter
Param(0) = New ReportParameter("ReportParameter1",TextBox1.Text)
Me.ReportViewer1.LocalReport.SetParameter(Param)
Me.ReportViewer1.RefreshReport
-------------------------------------------------------------------------------------------------------------
Here, ReportParameter1 is your parameter name in your report.
All Replies
WalangAlam,
Please add page header in your ReportViewer as the following steps:
1. Open a client report definition (.rdlc) file in graphical design mode.
2. On the Report menu, click Page Header. Page Header is toggle items on the Report menu. When enabled, a Page Header or Page Footer section appears on the design surface.
3. Alternatively, right-click in the empty area outside of the design surface, and then click Page Header.
Drag any of the following items from the Toolbox to the Page Header or Page Footer area: Textbox, Line, Rectangle,Image
4. Set properties on the Page Header or Page Footer to add borders, background images or colors, adjust width, or suppress headers or footers on the first page. To set these properties, right-click the Page Header or Page Footer area and select Properties.
The you can set the text in the controls on ReportViewer header according to your demand.
Hope that can help you.
Hi,
I have the same doubt and the points you have suggested are for the most common (in-built functions) text for eg. Date
In the case if i want to display a string taken from user and which is not a field in my database (Hence not in Dataset), how would i achive this.
For eg:
strComment = "Local Reporting"
Now i want this string to be printed on the report.
Any help would be thankful.
Hi,
Use a report parameter. In textbox value assign it to that parameter. In your code pass any value to the parameter and refresh the report. I thing it may help you.
It would be very helpful if you send me the snippet of code for the same.
Or consider the below scenoario:
I have a textbox on my form and a button.
I enter some text in the texbox and i want that to appear on the report.
Checkout the following link, go to the using - paramaters link in local mode - near the top left.
http://www.gotreportviewer.com/
Chris.
Insert a Textbox in your report and set the value of the textbox to the parameter. In the Win form,
First you need to import Windows.Reporting.Winform
On button click event,
-------------------------------------------------------------------------------------------------------------
Dim Param(0) as ReportParameter
Param(0) = New ReportParameter("ReportParameter1",TextBox1.Text)
Me.ReportViewer1.LocalReport.SetParameter(Param)
Me.ReportViewer1.RefreshReport
-------------------------------------------------------------------------------------------------------------
Here, ReportParameter1 is your parameter name in your report.
I see your problem and experienced it myself. I don't think you can use variables in an rdlc. Crystal Reports has it - they call it a 'formula'. I think this is the biggest thing missing from the Microsoft reporting tool....
Hey Arun,
Thanks for your help man, it worked!
Christy,
Here is the way how you can achive it:
-
Create a form and Drag a textbox component on the report and name it. (say rpt_txtComment)
-
Drag the "Report viewer" component on a new form for simplicity.
-
In the "Report viewer" component you can either select existing rdlc report or create a new one...
-
Open the RDLC report report in design mode.
-
While your "Report design view" window is active, click on the menu Report > Report Parameter...
-
A new window opens, here you can see one "ADD" button, click on it and add a new variable and name it (say rpt_Comment), you can set other attributes as well if required.
-
Now your report has the parameter (i.e. rpt_Comment) which can be populated by the code and can take input from the user. Following code describes passing the value to the Report:
Code BlockDim Param(0) as ReportParameter
Param(0) = New ReportParameter("rpt_Comment",TextBox1.Text)
Me.ReportViewer1.LocalReport.SetParameter(Param)
Me.ReportViewer1.RefreshReport
Similary you can add as many parameters you want to add.
Thanks once again to Arun in helping me out of this.
Any more doubts feel free to ask.
-
It seems to me that what Christy means is that RDLC do not support variables defined and updated from within the report.
If there is someone out there who knows a way to define a variable within an RDLC and change its value while the report is running, I like to know how?? thanks
4u2u
- THANK YOU THANK YOU THANK YOU!
3 days on this issue - and this actually was the clearest explination yet! My program works and now I can keep moving forward!
Thank you!
RichRider


