In this article I am going to show how we can show
crystal report with search functionality in asp.net with c#. Here I am going to
display Employee report . User can see any employee report by typing his/her
name.
Now we will learn this step by step:
Below is my SQL server table, for which I will show
crystal report.

Image 1.
Open Visual Studio -> File -> New Web Site.

Image 2.
Right Click on Solution Explorer -> Add New Item
-> Select Data Set

Image 3.
Now Right click -> Add -> Data Table

Image 4.
Now Right Click on Header -> Add ->Column
Make sure column name and their Data type should be same as in your data table.
You can change data type by selecting your added column ->Right click and select
Data type property

Image 5.
Now Right click on solution explorer -> Add New Item
-> Select Crystal Report

Image 6.

Image 7.
Select Project Data -> ADO.NET Data Sets-> Your
Created Data Set -> Your Table -> Click Next

Image 8.
Now select column for report and click on finish.

Image 9.
Now on your aspx page add a text box , button and a
report viewer like below:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="EmployeeReport.aspx.cs"
Inherits="EmployeeReport"
%>
<%@ Register
Assembly="CrystalDecisions.Web,
Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web"
TagPrefix="CR"
%>
<!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>Employee Report</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<table
cellpadding="10"
cellspacing="10"
width="70%"
height="300px"
align="center"
style="border: solid 2px gray;">
<tr>
<td align="center" style="background-color:
SkyBlue;">
Employee Name:#
<asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox>
<asp:Button ID="btnShowReport" runat="server" Text="Show Report" OnClick="btnShowReport_Click" />
</td>
</tr>
<tr>
<td align="center">
<asp:Panel ID="pnlReport" runat="server" Height="400px">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true"
/>
</asp:Panel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Now aspx.cs code is:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using
CrystalDecisions.CrystalReports.Engine;
public partial
class EmployeeReport
: System.Web.UI.Page
{
SqlConnection con;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new
DataSet();
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
btnShowReport_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=MyPC\SqlServer2k8;Integrated
Security=True;Initial Catalog=Test");
da = new SqlDataAdapter("select * from Employee where EmployeeName like
'%" + txtEmployeeName.Text + "%'
", con);
da.Fill(ds);
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("ShowEmployeeReport.rpt"));
rd.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rd;
}
}
Now run the application:
Click on Show Report button to display report.

Image 10.
Enter Employee First name and click on Show Report Button to display report.

Image 11.