RDLC Report in .NET 4.0
Please follow the below steps:
- Take .Xsd file (typed dataset) and create a table in this Typed dataset. This file must be in the App_Code folder.
- Build your Project/website.
- Now take .aspx Page and add reportviewer control in this file and choose RDLC report from reportviewer control.
- In RDLC wizard select Dataset (.xsd file added by you).
- Add All Column of Dataset (of .xsd) in required postion in RDLC file(you can tool table/text boxes from RDLC toolbox).
- 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).
- Use Script Manager (in aspx file) as this is manadatory.
- 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
Post a Comment