Thursday, 10 April 2014

How to create a RDLC report using ASP.NET with C# /VB.NET

Hi friends,in this article I will explain about How to Create Simple RDLC Report in ASP.NET.
I already explained in the previous articles about Filter and Sorting in GridView using DataView in ASP.NET using C#/VB.NET,How to Maintain selected Checkboxes state while paging in GridView? and Create your own captcha image generator in ASP.NET using C#.NET/VB.NET
In ASP.NET page add the below lines in the top of the page after page directive.

RDLC: (Report Definition Language Client-side)
The ReportViewer control supports a local processing mode that allows you to run client report definition (.rdlc) files using the built-in processing capability of the control. The client reports that you run in local processing mode can be easily created in your application project. There are four approaches to creating the report:
·         Create a new client report definition (.rdlc) file using the Report Wizard.
·         Create a new client report definition (.rdlc) file in Visual Studio.
·         Generate a report definition programmatically.

What is RDLC:
·         RDLC reports do not store information about how to get data.
·         RDLC reports can be executed directly by the ReportViewer control.
·         RDLC can be run completely client-side in the ReportViewer control.
·          This removes the need for a Reporting Services instance, and even removes the need for any database connection whatsoever; but it adds the requirement that the data that is needed in the report has to be provided manually. 
·         RDLC reports do not store information about how to get data. RDLC reports can be executed directly by the ReportViewer control.


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

Right click on Root folder add new item select Report Wizard
How to create a RDLC report using ASP.NET with C# /VB.NET

Click on Add button then the below popup will appear.Click on New  button then the second popup will open.

How to create a RDLC report using ASP.NET with C# /VB.NET

Set the Connection and click on Next then the database objects will come according to selected  database

How to create a RDLC report using ASP.NET with C# /VB.NET

Check the table and click on Finish  button.Then the fields will added.

How to create a RDLC report using ASP.NET with C# /VB.NET

Select Available fields and Drag and Drop to Values what you want.

How to create a RDLC report using ASP.NET with C# /VB.NET

After click on Next button the below screen will come.Choose the style and click on Finish button.

How to create a RDLC report using ASP.NET with C# /VB.NET


Choose the Report 
How to create a RDLC report using ASP.NET with C# /VB.NET

In ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Create RDLC Report in VS 2010 and SQL Server 2008</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <Ac:ToolkitScriptManager ID="ScriptManager" runat="server" AsyncPostBackTimeout="3600">
    </Ac:ToolkitScriptManager>
    </div>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
        Font-Size="8pt" InteractiveDeviceInfos="(Collection)"  Width="1000px"
        WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
        <LocalReport ReportPath="ReportNew.rdlc">
            <DataSources>
                <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="RDLCDataSet" />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetData"
        TypeName="TESTDataSetTableAdapters.User_DetailsTableAdapter">
        <InsertParameters>
            <asp:Parameter Name="Username" Type="String" />
            <asp:Parameter Name="Password" Type="String" />          
            <asp:Parameter Name="Gender" Type="String" />
            <asp:Parameter Name="Country" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    </form>
</body>
</html>

In C#:Net:
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;

public partial class RDLCReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/ReportNew.rdlc");
            string conString = ConfigurationManager.ConnectionStrings["TESTConnectionString"].ConnectionString;
            DataSet ds = new DataSet();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
            SqlCommand cmd = new SqlCommand("Select User_ID,UserName,Gender,Country from User_Details", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            ReportDataSource datasource = new ReportDataSource("RDLCDataSet", ds.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(datasource);
        }
    }
}


In VB.NET:
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms

Partial Public Class ReportVb
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
            ReportViewer1.ProcessingMode = ProcessingMode.Local
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/ReportNew.rdlc")
            Dim conString As String = ConfigurationManager.ConnectionStrings("TESTConnectionString").ConnectionString
            Dim ds As New DataSet()
            Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)
            Dim cmd As New SqlCommand("Select User_ID,UserName,Gender,Country from User_Details", con)
            Dim da As New SqlDataAdapter(cmd)
            da.Fill(ds)
            Dim datasource As New ReportDataSource("DataSet1", ds.Tables(0))
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.DataSources.Add(datasource)
        End If
    End Sub
End Class


"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook page Aspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore  for free updates directly to your Email inbox . Watch my blog  for more articles."
"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook page Aspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog for more articles."

1 comment:

© 2012-2014 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.