Visual Basic > Visual Basic Forums > Visual Basic General > Use a variable as a text value of a textbox in a report viewer
Ask a questionAsk a question
 

AnswerUse a variable as a text value of a textbox in a report viewer

  • Monday, July 09, 2007 2:59 AMWalangAlam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Thursday, July 12, 2007 6:18 AMBruno YuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.

  • Sunday, October 14, 2007 12:55 PMArunkumar.B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Thursday, July 12, 2007 6:18 AMBruno YuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.

  • Thursday, October 11, 2007 4:56 AMDinesh Gadewal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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. 

  • Thursday, October 11, 2007 6:30 AMArunkumar.B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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.

  • Thursday, October 11, 2007 6:36 AMDinesh Gadewal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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.

     

  • Thursday, October 11, 2007 1:57 PMvideodv Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Checkout the following link, go to the using - paramaters link in local mode - near the top left.

     

    http://www.gotreportviewer.com/

     

    Chris.

     

  • Sunday, October 14, 2007 12:55 PMArunkumar.B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.

     

     

     

     

     

     

  • Friday, October 19, 2007 7:53 PMChristy3 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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....

     

  • Thursday, November 08, 2007 9:00 AMDinesh Gadewal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hey Arun,

     

    Thanks for your help man, it worked!

     

    Christy,

    Here is the way how you can achive it:

     

    1. Create a form and Drag a textbox component on the report and name it. (say rpt_txtComment)
    2. Drag the "Report viewer" component on a new form for simplicity.
    3. In the "Report viewer" component you can either select existing rdlc report or create a new one...
    4. Open the RDLC report report in design mode.
    5. While your "Report design view" window is active, click on the menu Report > Report Parameter...
    6. 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.
    7. 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 Block

    Dim 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.

  • Monday, May 05, 2008 1:57 PMa4u2u Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Thursday, November 05, 2009 12:00 AMRichRider Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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