Quick & Dirty Report Writer, you need the NetstairReporting.dll --> download .DLL here
NetstairReporting.zipI am using the northwind database for this example download here -->
instnwnd.zip You can use your own.
Toolbar with Paging, Export to Excel, CSV and Printing, just like Crystal or SSRS
Default.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestReporting._Default" %>
<%@ Register Assembly="NetstairReporting" Namespace="NetstairReporting" TagPrefix="nc" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<style type="text/css">
body {font-family: verdana, arial, serif; font-size: 8pt; vertical-align: middle; }
.column-title { font-weight: bold; background-color: #4169E1; color: white;}
</style>
<script type="text/javascript" src="/scripts/ncTools.js"></script>
<main>
<section class="row" aria-labelledby="aspnetTitle">
<h1 id="aspnetTitle">ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.</p>
<p><a href="http://www.asp.net" class="btn btn-primary btn-md">Learn more »</a></p>
</section>
<div class="row">
<asp:Panel ID="pnlRpt" ScrollBars="Auto" Height="540px" runat="server">
<p style="text-align: center;">
<nc:ToolMenuBar ID="pgRpter" runat="server" />
</p>
<div id="print_area">
<asp:Panel ID="pnList" runat="server">
<asp:Repeater runat="server" ID="SReport_List">
<HeaderTemplate>
<table id="rptable" class="table table-bordered" width="100%" cellspacing="0">
<thead>
<tr class="column-title">
<th style="text-align: center;">ID</th>
<th>Name</th>
<th style="text-align: center;">Telephone</th>
<th>Title</th>
<th>City</th>
<th style="text-align: center;">Country</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody class="bg-white">
<tr>
<td style="text-align: center;">
<%# Eval("customerId") %>
</td>
<td>
<%# Eval("contactName") %>
</td>
<td style="text-align: center;">
<%# Eval("phone") %>
</td>
<td>
<%# Eval("contactTitle") %>
</td>
<td>
<%# Eval("city") %>
</td>
<td style="text-align: center;" >
<%# Eval("country") %>
</td>
</tr>
</tbody>
</ItemTemplate>
<FooterTemplate>
<tr>
<td colspan="8" style="font-weight: bold; color: red; text-align: center;">
<asp:Label ID="lblEmptyData" runat="server" Visible='<%# ((Repeater)Container.NamingContainer).Items.Count == 0 %>' Text="No record encountered. / Listado no disponible." />
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</div>
</asp:Panel>
</div>
</main>
</asp:Content>
Default.aspx.cs
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestReporting
{
public partial class _Default : Page
{
protected void Page_Init(object sender, EventArgs e)
{
this.pgRpter.btnFirstRow.Command += btnFirstRow_Click;
this.pgRpter.btnPrevious.Command += btnPrev_Click;
this.pgRpter.btnNext.Command += btnNext_Click;
this.pgRpter.btnLastRow.Command += btnLastRow_Click;
this.pgRpter.btnExportCSV.Command += btnExportoCsv_Click;
this.pgRpter.btnExportXLS.Command += btnExportoXls_Click;
this.pgRpter.btnPrint.Command += btnPrint_Click;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.pnlRpt.Visible = false;
LoadReportDataListing();
}
}
protected void btnCloseToolBar_Click(object sender, EventArgs e)
{
Response.Redirect("~/Home");
}
protected void btnExecute_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
this.pnlRpt.Visible = false;
LoadReportDataListing();
if (pgRpter.PagingCount > 0) { this.pnlRpt.Visible = true; }
}
}
protected void LoadReportDataListing()
{
try
{
string TSQL = "SELECT [CustomerID],[CompanyName],[ContactName],[ContactTitle],[Address],[City],[Region],[PostalCode],[Country],[Phone],[Fax] FROM[northwind].[dbo].[Customers]";
this.pgRpter.SqlConnectionString = ConfigurationManager.ConnectionStrings["PrimaryConnection"].ToString();
this.pgRpter.PagingSize = 25;
this.pgRpter.PagingDataSource(TSQL);
this.pgRpter.lblPagingMessage.Text = this.pgRpter.PagingMessage;
//- Bind to Repeater
SReport_List.DataSource = this.pgRpter.Paging_DataSource;
SReport_List.DataBind();
if (pgRpter.Row_Count>0)
{
this.pnlRpt.Visible = true;
}
}
catch (Exception ex1)
{
Console.WriteLine(ex1.Message.ToString());
}
}
protected void btnFirstRow_Click(object sender, System.EventArgs e)
{
this.pgRpter.CurrentPage = 0;
//- Reload control
LoadReportDataListing();
}
protected void btnPrev_Click(object sender, System.EventArgs e)
{
this.pgRpter.CurrentPage -= 1;
//- Reload control
LoadReportDataListing();
}
protected void btnNext_Click(object sender, System.EventArgs e)
{
this.pgRpter.CurrentPage += 1;
//- Reload control
LoadReportDataListing();
}
protected void btnLastRow_Click(object sender, System.EventArgs e)
{
this.pgRpter.CurrentPage = this.pgRpter.LastPage - 1;
//- Reload control
LoadReportDataListing();
}
protected void btnExportoCsv_Click(object sender, System.EventArgs e)
{
string TSQL = "SELECT [CustomerID],[CompanyName],[ContactName],[ContactTitle],[Address],[City],[Region],[PostalCode],[Country],[Phone],[Fax] FROM[northwind].[dbo].[Customers]";
this.pgRpter.SqlConnectionString = ConfigurationManager.ConnectionStrings["PrimaryConnection"].ToString();
this.pgRpter.ExporToCSVFile(TSQL, "");
}
protected void btnExportoXls_Click(object sender, System.EventArgs e)
{
Repeater repeater = (Repeater)SReport_List;
repeater.ID = "SSReport_List";
this.pgRpter.Export2Excel(repeater);
}
protected void btnPrint_Click(object sender, System.EventArgs e)
{
string TSQL = "SELECT [CustomerID],[CompanyName],[ContactName],[ContactTitle],[Address],[City],[Region],[PostalCode],[Country],[Phone],[Fax] FROM[northwind].[dbo].[Customers]";
this.pgRpter.SqlConnectionString = ConfigurationManager.ConnectionStrings["PrimaryConnection"].ToString();
this.pgRpter.ExporToHtml(TSQL, "~/export/",7);
}
}
}
Happy Coding!