Display crystal report according to value given in textbox in asp.net [Resolved]

Posted by Jitenkumar under ASP.NET on 9/1/2013 | Points: 10 | Views : 10893 | Status : [Member] | Replies : 1
Display crystal report according to value given in textbox in asp.net




Responses

Posted by: Satyapriyanayak on: 9/1/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ReportViewer.WebForm1" %>


<%@ 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="btn_display" runat="server" Text="Display" onclick="btn_display_Click"
/>
</div>

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />

</form>
</body>
</html>



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.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace ReportViewer
{
public partial class WebForm1 : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter sqlda = new SqlDataAdapter();
SqlCommand com = new SqlCommand();
DataTable dt;
DataSet1 ds = new DataSet1();
ReportDocument rptDoc = new ReportDocument();

protected void btn_display_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
dt.TableName = "Crystal Report Example";
com.Connection = conn;
com.CommandText = "Select * from product where ProductName='" + TextBox1.Text + "'";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
ds.Tables[0].Merge(dt);
rptDoc.Load(Server.MapPath("CrystalReport1.rpt"));
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
}
}
}


If this post helps you mark it as answer
Thanks

Jitenkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response