none
Change a Reports Label Text RRS feed

  • Question

  • How do you change a report label used in a report?

     

    I created a treeview on a form, along with a report viewer. The treeview is like

     

    Plant1

       2006

          March

       2007

          January

          March

     

    The user can select what month they would like and the label is fine, it shows the month with no problem, but when the user selects the year, the label reflects a month instead of the year.

     

    The data shows monthly and yearly as it should but, the label is the issue.

     

    I am using a dataview to filter the report

     

    How can you dynamically change the label on the report to what you want based on the filter expression applied in VB?

     

    Thanks Again

    Davids LEarning

       

    Thursday, October 4, 2007 9:38 PM

All replies

  • Hi again, David,

     

    What is the current expression you are using for the textbox in the label?  In what band does the textbox appear?

     

    You may, just as in your previous question, have plenty of information in the report data itself to figure out what the label should be.  For example you may be able to write an expression that compares the First() date to the Last() date for a field that is contained in the report.  If they are not the same, then display the year in the label.  If they are the same, display the month.

     

    If you do not have enough information in the report data to write the expression, you can, as discussed in previous thread, pass a parameter to the report letting it know what the filter is.  You can pass the literal value of the filter, if you like, and then your textbox expression can parse it for the correct result.  Alternatively, you can format a nice string in your VB application, send that as the parameter, and simply display the parameter value in the report label without additional work.

     

    Does this make sense?

     

    >L<

     

    Sunday, October 7, 2007 3:41 PM
  • Hey there, nice of you to catch this thread, been fishing?<s>

     

    Alright, I have fiqured out how to use expressions in my report, by the way, thanks for teaching me how to fish, but I have not mastered a parameter yet.

     

    As to parameters, how do you use them?

    Got a good example?

     

     

    Davids Learning

    Monday, October 8, 2007 12:16 PM
  •  

    Hi again,

     

    1. To start out using parameters, you need to define them.  Have you found that yet?  It's on the Report menu popup.  You don't have to worry about the prompt, your users aren't going to be seeing this parameter.  

     

    If you are not sure how to reference the parameter in an expression: When you're in the expression dialog you have doubtless seen that Parameters are one of the options on the left side list.  Select that and doubleclick on your parameter name in the middle list and you'll see the appropriate syntax in the expression box.

     

    2. You will find a fully-worked example of programmatically assigning parameter values to the report at runtime here:

     

    http://spacefold.com/lisa/post/Another-bit-for-dynamic-ReportViewer-control-handling-Parameters-in-more-depth.aspx 

     

    You can ignore the stuff in that post about a REST-style interface, and the fact that the parameters that are being assigned are completely dynamic in this case (IOW, the code doesn't have a clue what it's assigning). 

     

    The lines of code that create a parameter object and hand them to the report are exactly the same for you as you'll see there, with the possible exception of being winforms instead of webforms and probably addressing localreport instead of serverreport.  It will work the same way.

     

    In that example, I am showing how to assign parameters when the report first loads in a web page.  If, like many people, you need to re-load data and re-assign the parameter values, you will find a fully-worked example of doing that in context (this time using localreport and winform!) here:

     

    http://spacefold.com/lisa/post/Dynamically-loading-reports-in-ReportViewers.aspx

     

    In this walkthrough, which doesn't concentrate on parameters, you'll see an appropriate sequence of events. You'll find only one parameter being assigned, with an explicit name, as part of that process.

     

    3. What's left to understand: what you want to put in that parameter value so that you can display it properly.  This depends on you.  As I said, your external code can put the literal filter value there and the report expression can parse it smartly (ask if you need help), *or* you can choose to fashion the exact label you want, externally, and then the report expression simply references the parameter value as-is.

     

    Later,

     

    >L<

    Monday, October 8, 2007 3:06 PM