This is a migrated thread and some comments may be shown as answers.

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

2 Answers 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott McNeany
Top achievements
Rank 1
Scott McNeany asked on 27 Oct 2010, 03:15 PM
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.

Thanks,

Scott

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)
            {
                Elmah.ErrorSignal.FromCurrentContext()
                    .Raise(new Exception(string.Format(
                        "An attempt was made to execute report 'Compensation Report' with invalid parameter '{0}'. This indicates a bug.", li.Value)));
            }
        }

        report.SetSortColumn(
            ddlSortColumn.SelectedValue, 
            (Telerik.Reporting.Data.SortDirection)Enum.Parse
            (typeof(Telerik.Reporting.Data.SortDirection), ddlSortDirection.SelectedValue, true));
        
        this.ReportViewer1.Report = report;
    }

2 Answers, 1 is accepted

Sort by
0
Scott McNeany
Top achievements
Rank 1
answered on 27 Oct 2010, 03:21 PM
I guess I should ask "How do you preserve the 'ReportParameters' collection" during the lifecycle?
0
Steve
Telerik team
answered on 29 Oct 2010, 04:47 PM
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,
Steve
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
Tags
General Discussions
Asked by
Scott McNeany
Top achievements
Rank 1
Answers by
Scott McNeany
Top achievements
Rank 1
Steve
Telerik team
Share this question
or