Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Crystal Report in ASP.NET With Search Functionality

Viewed:  2259 
Posted On:  14/09/2014 07:04:22 
How we can display a crystal report with search functionality in c#? 


In this article I am going to show how we can show crystal report with search functionality in 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" "">
<html xmlns="">
<head runat="server">
    <title>Employee Report</title>
    <form id="form1" runat="server">
        <table cellpadding="10" cellspacing="10" width="70%" height="300px" align="center"
           style="border: solid 2px gray;">
                <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 align="center">
                    <asp:Panel ID="pnlReport" runat="server" Height="400px">
                        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
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);
        ReportDocument rd = new ReportDocument();
        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.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us