data sources which was registered in the report by a programming method

Ozan K. BAYRAMOzan K. BAYRAM Istanbul
edited 8:35PM in FastReport .NET
Hi, i'm new to Fast Report .NET.

I red that "i can choose one of the data sources which was registered in the report by a programming method" in the user manual (http://fast-report.com/documentation/UserManFrNET-en/selectreportdata.htm)

How i can perform this? How can i register a data source by a programming method?

For example i have an object like List<string> and wanted to show as a report.

How can i create a frx file that lists my object content? What is missing with the code below?

Thanks in advance!
        List<string> items = new List<string>();

        items.Add("1a askdfh askfhklas fh");
        items.Add("asgflaskjf laskjflasf");
        items.Add("asf asjlşfjaslfj aslşfas");
        items.Add("asf?§jas lfjaslÅŸfj salf");
        items.Add("asfasj flasjlşfj aslf");
        items.Add("asflkasjflasfjşlasdjlf");

        Reports.DetailedProductGroupList report = new Reports.DetailedProductGroupList(); //this is a class saved from a .frx file. It only contains a label that shows name of the report.
        report.RegisterData(items, "items");
        report.GetDataSource("items").Enabled = true;
        WebReport1.Report = report;

Comments

  • edited 8:35PM
    Hello,

    You may use the following scenario to create a report in webmode:
    http://www.fast-report.com/en/forum/?p=/discussion/6475
  • Ozan K. BAYRAMOzan K. BAYRAM Istanbul
    edited 8:35PM
    this doesn't make any sense to me!

    what about my scenario?
  • edited March 2010
    In your scenario, there is no datasource at the time when you create a report. How do you create a report with no datasource? You need to put some Text objects on a databand, write something like
    [Table.Column1] [Table.Column2] ...
    in them. You may easily make a mistake because you need to type table/column names, there is no way to drag/drop them.
    Then you need to register a datasource with the "Table" name (because you use this name in the Text objects), and attach the databand to that datasource.

    In your case you need to put single Text object on the databand, and write the following text in it:
    [items.Value]
    In your code:
    report.RegisterData(items, "items");
    report.GetDataSource("items").Enabled = true;
    report.Data1.DataSource = report.GetDataSource("items");
    WebReport1.Report = report;
    
  • Ozan K. BAYRAMOzan K. BAYRAM Istanbul
    edited March 2010
    i've added [items.value] as label to data band. and saved .frx file as report.

    then edit this new class' namespace because it is 'FastRepor' by default

    i tried to compile class library and get the following error

    Error 7 The name 'items' does not exist in the current context D:\Sources\MyWise\Reports\DetailedProductGroupList.cs 32 16 Reports

    Do i have to add another thing to report? (parameter etc.)

    Thanks in advance
  • edited 8:35PM
    I'm afraid this will not work with the "report as a class". You still may use this approach with the report stored as .frx file:
    Report report = new Report();
    report.Load(frxfile);
    report.RegisterData(items, "items");
    report.GetDataSource("items").Enabled = true;
    (report.FindObject("Data1") as DataBand).DataSource = report.GetDataSource("items");
    WebReport1.Report = report;
  • Ozan K. BAYRAMOzan K. BAYRAM Istanbul
    edited March 2010
    one of my collegue made it work with both methods. we're having a problem with generic list i think...
                    DBDataContext db = new DBDataContext();
    
                    var products = from p in db.Products
                                   select p;
    
                    //as a report file
                    string reportFile = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) + @"Reports\test.frx";
                    Report report1 = new Report();
                    report1.Load(reportFile);                
                    report1.RegisterData(products.AsEnumerable(), "Products");
                    ((DataBand)report1.Pages[0].ChildObjects[2]).DataSource = report1.GetDataSource("Products");
                    report1.Prepare();
                    reportViewer.Report = report1;
    
                    //as a class
                    FastReport.test report = new test();
                    report.RegisterData(products.AsEnumerable(), "Products");
                    report.dataProducts.DataSource = report.GetDataSource("Products");
                    report.Prepare();
                    reportViewer.Report = report;
    
  • edited 8:35PM
    AlexTZ wrote: »
    I'm afraid this will not work with the "report as a class". You still may use this approach with the report stored as .frx file:
    Report report = new Report();
    report.Load(frxfile);
    report.RegisterData(items, "items");
    report.GetDataSource("items").Enabled = true;
    (report.FindObject("Data1") as DataBand).DataSource = report.GetDataSource("items");
    WebReport1.Report = report;

    Hi, I newbi, I,m intented use this code, but my report have a group and sendme this error en de web
    GroupHeader1): error BC30034: Bracketed identifier is missing closing ']'.
    (Text4): error BC30451: Name 'nomina' is not declared.

    have declare datasource for gruop elements and footer ?, how declare ?

    regaders
  • edited 8:35PM
    Hello,

    Probably you make a type in the tablename.columnname in your report, or you have not registered the datasource with the correct name. I need a test application from you to find an error. If you able to create such application, please send it to tz@fast-report.com.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.