Posts Tagged ‘Reports View’

Report Viewer Control

March 18, 2008

Steps for creating Web Control Library

from VS IDE Select FIle>New>Project>WebControlLibrary

As in following Image :

Web Control Lib


Try this code for creating Report Viewer Control to cs file:

//Author:Nissan .K. George
//Web Developer
//nissankg@yahoo.com

using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Data;
using Microsoft.Reporting.WebForms;
namespace DBReportViewer
{
[DefaultProperty(“DataTable”), ToolboxData(“<{0}:DBReportViewer runat=server></{0}:DBReportViewer>”)]

public partial class DBReportViewer : Microsoft.Reporting.WebForms.ReportViewer
{
[Bindable(true)]
[Category(“Appearance”)]
[DefaultValue(“”)]
[Localizable(true)]

#region “Properties”

private string objectTypeName;
[Bindable(true),
DefaultValue(“”)]

public string ObjectTypeName
{
get { return objectTypeName; }
set { objectTypeName = value; }
}

private DataTable DatatableSource;
public DataTable DataTableSource
{
get
{
return DatatableSource;
}

set
{
DatatableSource = value;
}
}
private Object objectSource;
public Object ObjectSource
{
get
{
return objectSource;
}

set
{
objectSource = value;
}
}

private string XmlDataSetName;

public string XMLDataSetName
{
get
{
return XmlDataSetName;
}

set
{
XmlDataSetName = value;
}
}
private string reportpath;

public string ReportPath
{
get
{
return reportpath;
}

set
{
reportpath = value;
base.LocalReport.ReportPath = value;

}
}

#endregion

#region Members overrides
//protected override void RenderContents(HtmlTextWriter output)
//{

// output.Write(Text);
//}

// METHOD:: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

Type t = this.GetType();

}

// METHOD:: OnPreRender
protected override void OnPreRender(EventArgs e)
{
// Do as usual
base.OnPreRender(e);

}
public override void DataBind()
{

try
{
if ((XMLDataSetName == null) && (DatatableSource == null) && (objectSource == null))
{

base.LocalReport.DataSources.Add(new ReportDataSource());

}
else if ((XMLDataSetName == null) && (DatatableSource != null))
{

base.LocalReport.DataSources.Add(new ReportDataSource(“DB”, DatatableSource));

}
else if ((XMLDataSetName != null) && (DatatableSource != null))
{

base.LocalReport.DataSources.Add(new ReportDataSource(XMLDataSetName, DatatableSource));
}
else if ((ObjectSource != null) && (ObjectTypeName != null))
{

base.LocalReport.DataSources.Add(new ReportDataSource(ObjectTypeName, ObjectSource));
}

base.DataBind();

base.LocalReport.Refresh();
}
catch (Exception ex)
{
throw ex;
}
}

#endregion

}
}
after creating control add dll to toolkit then drag into page for use

use following code :

private void loadReports()
{
int allReopts = 1;
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();

MarketingReportView.LocalReport.ReportEmbeddedResource = “DB.Portal.Maintenance.MarketingReports.ReportTemplates.ActiveTrialReport.rdl”;

startDate = DateTime.Now.Date;
endDate = DateTime.Now.Date;
MarketingReportView.LocalReport.DataSources.Clear();

Sherston.Portal.BusinessData.Common.DataList<School> obj = SchoolService.GetSchoolsSubscriptionReports(SchoolService.ReportType.ActiveTrialUsersReport, startDate, endDate, allReopts, 0, 0);
MarketingReportView.ObjectSource = obj;

MarketingReportView.ObjectTypeName = “PortalDataSource”;
MarketingReportView.DataBind();

}

Advertisements