Report Constructor runs 3 times and values set in between are lost

3 posts, 0 answers
  1. Scott McNeany
    Scott McNeany avatar
    9 posts
    Member since:
    Mar 2010

    Posted 27 Oct 2010 Link to this post

    I'm trying to set available columns as a list and allow callers to make them visible at run-time. Maybe I'm trying to do too much with the available tools, but my approach is much preferred over traditional report parameters for the following reasons:

    1. I can define columns programmatically and make them available as a list to the callers without the caller having to know the column names at compile-time.
    2. Callers can choose which columns to make visible, change the size, etc at run-time.

    So basically I have a List<ReportColumn> collection and a List<SortableColumn> collection. I populate these collections in the report constructor.

    I then bind a checkbox list in the caller to allow the user to specify which columns to show. I also bind a drop-down to allow the user to pick which column to sort on.

    I then have methods ShowHideColumn(string key, bool visible) and SetSortColumn(string key, SortDirection direction) available for the caller to chose which columns to show and sort by.

    My problem is that setting these properties on the list are simply wiped away the next time the constructor is run. Is there a way to preserve these values. Web caching perhaps? I'd rather not use caching if there is a better way to preserve them, but i will do what i have to to preserve the binding functionality.



    protected void btnRunReport_Click(object sender, EventArgs e)
            CompensationStatement report = new CompensationStatement();
            report.ReportParameters["ProducerNumber"].Value = ddlProducerNumber.SelectedValue;
            report.ReportParameters["Month"].Value = DateTime.Parse(ddlMonth.SelectedValue);
            //Indicate which columns to show.
            foreach (ListItem li in cblstAvailableColumns.Items)
                bool columnExists = report.ShowHideColumn(li.Value, li.Selected);

                if (!columnExists)
                        .Raise(new Exception(string.Format(
                            "An attempt was made to execute report 'Compensation Report' with invalid parameter '{0}'. This indicates a bug.", li.Value)));

                (typeof(Telerik.Reporting.Data.SortDirection), ddlSortDirection.SelectedValue, true));
            this.ReportViewer1.Report = report;
  2. Scott McNeany
    Scott McNeany avatar
    9 posts
    Member since:
    Mar 2010

    Posted 27 Oct 2010 Link to this post

    I guess I should ask "How do you preserve the 'ReportParameters' collection" during the lifecycle?
  3. DevCraft R3 2016 release webinar banner
  4. Steve
    Steve avatar
    10941 posts

    Posted 29 Oct 2010 Link to this post

    Hello Scott,

    The best thing about our product is that it is very feasible and allows for various scenarios to be done with little to no effort:
    • for creating a tabular report with variable user selected number of columns, please refer to the attached project.
    • see the following forum thread elaborating on creating interactive sorting controlled by the user.

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top