I m suing crystal report for printing all the monthly bills on a single click. Problem i m facing is the loop and other ode is working fine but the ystal report viewer is showing only the last bill to print.
I m posting my code plz check
aspx page code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Prints.aspx.cs" Inherits="invenrtymanagement.Prints" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
<CR:CrystalReportSource ID="rptDoc" runat="server" ></CR:CrystalReportSource>
</div>
</form>
</body>
</html>
.cs page code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
namespace invenrtymanagement
{
public partial class Prints : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
SqlDataAdapter da;
DataTable dt;
SqlCommand cmd;
string sstr;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
try
{
int t;
SqlDataAdapter da105 = new SqlDataAdapter("select BillNo from Customer_Bill where mode='0'", con);
DataTable dt105 = new DataTable();
da105.Fill(dt105);
for (t = 0; t < dt105.Rows.Count; t++)
{
//System.Threading.Thread.Sleep(10000);
ReportDocument rptDoc = new ReportDocument();
DataSet1 ds = new DataSet1();
DataTable dt = new DataTable();
dt.TableName = "Crystal Report Example";
SqlDataAdapter da = new SqlDataAdapter("select * from companyprofile a join Customer_Bill b on a.states=b.LedgerAccountID join bill_details c on b.BillNo=c.BillNo where b.BillNo ='"+ dt105.Rows[t][0].ToString() +"'", con);
da.Fill(dt);
ds.Tables[0].Merge(dt);
rptDoc.Load(Server.MapPath("CrystalReport1.rpt"));
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
//cmd = new SqlCommand("update Customer_Bill set mode='1' where BillNo='" + dt105.Rows[t][0].ToString() + "'", con);
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
//break;
}
//int t;
// SqlDataAdapter da105 = new SqlDataAdapter("select BillNo from Customer_Bill where mode='0'", con);
// DataTable dt105 = new DataTable();
// da105.Fill(dt105);
// for (t = 0; t < dt105.Rows.Count; t++)
// {
// sstr = dt105.Rows[t][0].ToString();
// cdetail();
// dataname();
// showgrid();
// adr();
// ScriptManager.RegisterStartupScript(Page, GetType(), "dvQuotation", "doPrint();", true);
// //btnPrint.OnClientClick = ;
// //this.btnPrint.Click = true ;
// }
//
}
catch (Exception ex)
{
Response.Redirect(ex.Message);
}
}
public void print_page()
{
// Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "doPrint();", true);
}
}
}
I need your urgent attention.