Skip to main content

RDLC Report in .NET 4.0

RDLC Report in .NET 4.0

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>

Comments

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.