RDLC報表系列——–初級報表

來源:互聯網
上載者:User

前面記錄下了很多平時開發遇到的問題,RLDC之前也是不會,只會水晶報表,後來也慢慢的也上手了。把這些記錄下來,以後用的著

1.開啟VS添加建立項,選擇Reporting,選擇報表,尾碼名為RLDC的名稱自取。

2.添加資料集.xsd,添加表,添加欄位,欄位名和DataTable內的欄位大小寫相同,類型 數字類型和日期類型需要改,因為在報表中數字和日期需要格式化.如果string類型格式化將不起作用或者需要類型轉換.

3.添加頁面,註冊報表命名空間,

  <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

添加

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

添加 報表

   <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
                    InteractiveDeviceInfos="(集合)" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
                    Height="98%" Width="99%">
                    <LocalReport ReportPath="BS\SalReport\CaseRecoveryReport.rdlc"> //報表位置的路徑
                    </LocalReport>
                </rsweb:ReportViewer>

4.代後代碼 添加資料到報資料表空間

 protected void Page_Load(object sender, EventArgs e)
        {
           if (!IsPostBack)
            {
                 ReportViewer1.Visible = true;

                 Display();
            }
        }

       void Display()
        {

            ReportViewer1.Visible = true;
            //報表資料來源
            DataTable dt = new Tq_DepSale().GetTQ_ShiftPay(fOrgNo, StartTime, EndTime, fShiftNo);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));  //這個DataSet1 需和報表裡資料集同名
            ReportViewer1.LocalReport.Refresh();
        }

5.設計報表

 開啟第一步添加的報表檔案

右側會出現報表相關的控制項等,選擇新將資料集 彈出資料集視窗,資料名預設為DataSet1 這裡如果改名 則代碼裡需要同名,資料集選擇第二步添加的xsd資料集檔案,可用資料選擇資料集中的表。OK完成則右側會出現資料欄位列表。

6.選擇工具列 將表拖到報表空白處,將右側的資料表欄位托到表格中或者點擊表格會出現一個表徵圖,將欄位選中就可以。完成後表格大小調整下。基本上最簡單的報表完成。執行查詢效果.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.