Step is based on Microsoft Visual Studio 2013
Step 1:
1. Create a
new website.
2.
Right-click on Website => Select Add => Select and Click
on New Item…
3. Popup
Windows Open => Select Data Tab from left pane =>
Select DataSet from Middle pane
4. Click
on Add
5. DataSet1.xsd added
in your Project
6.
Open DataSet1.xsd
7. Right
Click on the Dataset Designer => Select Add =>
Select and Click on DataTable
8. DataTable1 added
on the DataSet Designer
9. Right
Click on the DataTable1 => Select Add =>
Select and Click on Column => Give Column Name as you
preferred
10. Right
Click on the Column Name => Select and Click on Properties => Here you
can set or change the value
Step 2:
1.
Right-click on Website => Select Add => Select and Click
on New Item…
2. Popup
Windows Open => Select Reporting Tab from left pane =>
Select Report from Middle pane
3. Click
on Add
4. Report1.rdlc added
in your Project
5.
Open Report1.rdlc
6.
Select ReportData toolbox Windows from Left site
7. Select
and Right Click on Datasets => Click on Add
Datasets...
8. Dataset
Properties Windows Open
9. Give Name as you preferred
10. Data
Source Dropdown List you can see the DataSet1 Dataset
i.e. In Step 1 you was created, Select it
11. All the
field of DataTable1 are visible right side.
12. Click
on OK
13.
Select ReportData toolbox Windows from Left site => you
will see Under Datasets DataSet1 has been added
14. Right
Click on Report Design surface => Select Insert =>
Select and Click on Table => Table added on Report Design
surface
15. Open
ReportData toolbox Windows from Left site => Expand Datasets =>
Expand DataSet1
16. Drag and
Drop Column to Table i.e. added on Report Design surface in Step 14
Step 3:
1.
Right-click on Website => Select Add => Select and Click
on New Item…
2. Popup
Windows Open => Select Web Tab from left pane =>
Select Web Form from Middle pane
3. Click
on Add
4. WebForm1.aspx added
in your Project
5. Go
to Toolbox => Expand Reporting Tab =>
Drag and Drop ReportViewer on the page
Step 4: (WebForm1.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CreateReport.WebForm1" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Button ID="btnGenerateReport" runat="server" Text="Generate
Report" OnClick="btnGenerateReport_Click" />
</div>
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
Step 5:
Add Reference…
1. Right
Click on References => Click on Add Reference…
2. Popup
Windows Open => Expand Assemblies => Select Extensions =>
Select Microsoft.Reporting.WebForms 10.0.0.0 Checkbox
3. Click
on OK
4. Microsoft.Reporting.WebForms added
in your Project References folder.
Step 6: (WebForm1.aspx.cs)
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CreateReport
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected DataTable BindData()
{
DataTable dt
= new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dt.Columns.Add(new DataColumn("Column4", typeof(string)));
int totalRow
= 5;
for (int i
= 0; i < totalRow; i++)
{
dr = dt.NewRow();
dr["Column1"] = "Row" + i;
dr["Column2"] = "Row" + i;
dr["Column3"] = "Row" + i;
dr["Column4"] = 1000 / (i + 1);
dt.Rows.Add(dr);
}
return dt;
}
protected void btnGenerateReport_Click(object sender, EventArgs e)
{
string ReportFileName
= @"~/Report1.rdlc";
//This "DataSet1" should
be same as the Dataset name mentioned in the Report1.rdlc in
Step 2 Point no 9.
ReportDataSource rds
= new ReportDataSource("DataSet1",
BindData());
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.ReportPath = HttpContext.Current.Server.MapPath(ReportFileName);
ReportViewer1.LocalReport.Refresh();
}
}
}
Output
Note:-
If you are
getting following error
Error 1:
Add the following to <system.web> => <httpHandlers> section
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
After
adding code in web.config look like this
<system.web>
<httpHandlers>
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
</httpHandlers>
</system.web>
Add the
following to <system.webServer> => <handlers> section
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
After
adding code in web.config look like this
<system.webServer>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
Error 2:
Add the following to <system.webServer> section
<validation validateIntegratedModeConfiguration="false" />
After
adding code in web.config look like this
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
No comments:
Post a Comment