zoukankan      html  css  js  c++  java
  • 转:Dynamic Binding Of RDLC To ReportViewer

    Introduction

    I was struggling to find the solution to bind rdlc dynamically to reportviewer .We had a scenario were we migrated our application from .NET 1.1 to .NET 2.0 .After migration embedding reportviewer with explicit objectdatasource was creating a major issue. Whenever we try to assign dataset reference to objectdatasource the IDE shuts down abruptly for no reason. This was one of the bug we encountered while developing. We searched a lot but this unique problem was faced by very few hence the correct solution was not available. We then planned to bind the reportviewer at runtime without taking objectdatasource. Below is the procedure to go about it.

    Design Architecture

    Sample Image - maximum width is 600 pixels

    Production Deployment Issues And Its Resolution

    During deployment if the source code is published and precompiled is created, one has to be extra careful to do below activity.

    • Create precompiled for deployment.
    • Replace the .RDLC file from the precompiled source code with the original *.rdlc file. The reason behind this is precompiled corrupt the .rdlc internal code constructs. In order to maintain its schema and design we suggest you to replace the precompiled rdlc with original one.

    Prerequisite

    Note: In production web server we have light weight .net framework installed so report viewer is not available. Due to which it will throw report viewer dlls not exist.

    Click here to install Reportviewer.exe.

    Problem Statement

    There is customer table with two field customerid and customerName. We need to generate report for this datatable in reportviewer without usingobjectdatasource.

    Create Dataset Schema

    Follow the step given below to define dataset schema without connecting to any datasource. This is manual process. This is require each column of the table to added one by one as shown below.

    Sample Image - maximum width is 600 pixels

    Click on the toolbox icon to proceed further.

    Sample Image - maximum width is 600 pixels

    Add column to the schema as given below.

    Sample Image - maximum width is 600 pixels

    Create Report RDLC With Parameter

    One needs to drag table from toolbox to panel to draw table section as body part of report. Once done that click on Show Data Source one will view the dataset schema section as given below. Drag columns into table row just below header section. Select Reportparameter from main menu and add one to report. This parameter value can be passed from aspx's form to Reportviewer's RDLC panel.

    Sample Image - maximum width is 600 pixels

    Drag textbox in report screen and right click to select property of it.

    Sample Image - maximum width is 600 pixels

    Click on Fx button of value field to associate this textbox field value to parameter set field variable.

    Sample Image - maximum width is 600 pixels

    Sample Image - maximum width is 600 pixels

    Embed Report Viewer in Aspx

    Drag Reportviewer into aspx design page and add localpath of the RDLC file. One can invoke storeprocedure and get the database resultset and can assign it to reportviewer. For running a version of this demo, I included hardcoded resultset.

     Collapse
     private void BindReportViewer()
        {
            ReportViewer1.Visible = true;
                   
            //Invoke Stored procedure With Input parameter to it.
            //DataSet dsReport = objSP.GetTable(storedProcedure,txtParameter.Text));
            //Hardcoded Values.
            IList >Customer< customerList = new List>Customer<();
            customerList.Add(new Customer(1,"Santosh Poojari"));
            customerList.Add(new Customer(2, "Santosh Poojari1"));
            customerList.Add(new Customer(3, "Santosh Poojari2"));
           
            ReportParameter[] param = new ReportParameter[1];
            param[0] = new ReportParameter("Report_Parameter_0",txtParameter.Text);
            ReportViewer1.LocalReport.SetParameters(param);
    
            ReportDataSource rds = new ReportDataSource
    			("DataSet1_Customers_DataTable1", customerList);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
        }

    Below is the expected output.

    Sample Image - maximum width is 600 pixels

    Conclusion

    Hope this article will help those who are working on similar problem statement. Any suggestion and advice will help me to improve the quality of this article.

  • 相关阅读:
    Atitit.软件GUI按钮与仪表盘(01)报警系统
    Atitit.软件仪表盘(7)温度监测子系统电脑重要部件温度与监控and警报
    Atitit.异步编程 java .net php python js 的比较
    Atitit.mssql 数据库表记录数and 表体积大小统计
    Atitit.软件仪表盘(0)软件的子系统体系说明
    Atitit. 单点登录sso 的解决方案 总结
    .atitit.web 推送实现解决方案集合(3)dwr3 Reverse Ajax
    atitit..主流 浏览器 js 引擎 内核 市场份额 attialx总结vOa9
    Atitit.软件仪表盘(4)db数据库子系统监测
    Atitit.软件仪表盘(8)os子系统资源占用监测
  • 原文地址:https://www.cnblogs.com/techfans/p/4134959.html
Copyright © 2011-2022 走看看