Click here to Skip to main content
Click here to Skip to main content

Using RDLC Report in .NET 4.0

, 19 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Using RDLC report in .NET 4.0 version in ASP.NET and C#.

Introduction 

Using RDLC report in .NET 4.0 is quite different in comparison to prior versions of .NET. Since RDLC reports have their own importance, here are some easy steps to use them.

Using the code 

Please follow the below steps:

  1. Take .Xsd file (typed dataset) and create a table in this Typed dataset. This file must be in the App_Code folder.
  2. Build your Project/website.
  3. Now take .aspx Page and add reportviewer control in this file and choose RDLC report from reportviewer control.
  4. In RDLC wizard select Dataset (.xsd file added by you).
  5. Add All Column of Dataset (of .xsd) in required postion in RDLC file(you can tool table/text boxes from RDLC toolbox).
  6. Now Fill .xsd DataSet in code behind file.(please take care of this. see DataSet using in c#. I took same table name what is in my typed DataSet).
  7. Use Script Manager (in aspx file) as this is manadatory.
  8. Also use !IsPostBack in Page load to avoid infinte loop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;


public partial class Report_RDLC_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                DataSet DsTest = new DataSet("dtTest");
                DataTable dtTest = new DataTable("dtTest");
           
                dtTest.Columns.Add("EmpName", System.Type.GetType("System.String"));
                dtTest.Columns.Add("EmpId", System.Type.GetType("System.Int32"));
                dtTest.Columns.Add("EmpSal", System.Type.GetType("System.Double"));


                DataRow dr;
                for (int iIndex = 0; iIndex < 99; iIndex++)
                {
                    dr = dtTest.NewRow();
                    dr["EmpId"] = "100" + iIndex.ToString();
                    dr["EmpName"] ="Kapil Dev-  "+  iIndex.ToString();
                    dr["EmpSal"] = (iIndex * 32678).ToString();
                    dtTest.Rows.Add(dr);
                }
                DsTest.Tables.Add(dtTest);


                ReportViewer1.Visible = true;
                ReportDataSource datasource = new ReportDataSource("DataSet1", DsTest.Tables[0]);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(datasource);
                ReportViewer1.LocalReport.Refresh();      
            }
        }
        catch
        {

        }
    }
}
<%@ Page Language="C#" AutoEventWireup="true" 
  CodeFile="Default.aspx.cs" Inherits="Report_RDLC_Default" %>

<%@ Register 
  assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, 
    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
  namespace="Microsoft.Reporting.WebForms" 

tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            height: 34px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" >
        </asp:ScriptManager>
   <div style="text-align:center;width:80%;">
        
        
        <table style="width:60%;text-align:center;margin:0px 0px 0px 200px;">
        <tr>
        <td style="text-align:center" >
           <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
                BackColor="#CCCCFF" Height="600px" Width="100%">
            <LocalReport ReportPath="Report_RDLC\Report1.rdlc">
            </LocalReport>
        </rsweb:ReportViewer>
        
        </td>
        </tr>
        </table>    
    </div>
    </form>
</body>
</html>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

KapilDevTripathi
Technical Lead Tech Mahindra
India India
Working in Tech mahindra, Noida, India. Having more than 7 years knowledge in asp, ASP.net,C#, VB 6.0, VB.Net, XSLT, XML, RDLC report, Crystal Report, SQL Server, MySql, DB2 etc.

Comments and Discussions

 
QuestionCreating New Page for new Information of report.rdlc Pinmembermhamidnasir26-May-14 1:03 
QuestionUsing Business Objects PinmemberMember 207364411-Apr-13 6:46 
QuestionSend to printer Pinmemberdavid4life20-Nov-12 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 19 Nov 2012
Article Copyright 2012 by KapilDevTripathi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid