Asked by:
i want label printing in crystal report Asp.Net c#.

Question
-
User-367318540 posted
here is video for your consideration......
https://www.youtube.com/watch?v=i7NYevleSA0
i want this on web form....kindly consider...
Thursday, August 1, 2019 11:07 AM
All replies
-
User665608656 posted
Hi akhterr,
According to your needs, I found that the content of the video you give has little to do with the crystal report.
Do you want to embed the button of webform in the crystal report to print? Please tell us more detailed about it.
I've made a webform case to implement the same function in your video, you can refer to it:
I created two webform pages. In the first page, bootstrap modal model was used to implement parameter input and page number setting in videos.
After the input submission is completed, the input parameters are jumped to another page, the passed parameters are accepted on another page, and the current number of pages is looped in js.
In addition to the default div of the page, other divs are dynamically added and hidden, setting them to be displayed when the page is printed.
Remember to use .page-break class to separate pages when printing.
For more details, you could refer to the following code:
first page:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script type="text/javascript"> $(function(){ $('#modalLoginForm').modal('show'); $("#save").click(function(event ){ event.preventDefault(); alert("You saved!"); $('#modalLoginForm').modal('hide'); var containerNo = $("#modalLoginForm #containerNo").val(); var code = $("#modalLoginForm #code").val(); var nobales = parseInt($("#modalLoginForm #nobales").val()); window.location.href ='WebForm_print_mutilpepage.aspx?containerNo='+containerNo+"&code="+code+"&nobales="+nobales; }); }); </script> </head> <body> <form> <div class="modal fade" id="modalLoginForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header text-center"> <h4 class="modal-title w-100 font-weight-bold">Label Printing</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body mx-3"> <div class="md-form mb-5"> <label for="containerNo">Enter Container No</label> <input type="text" class="form-control" id="containerNo" /> </div> <div class="md-form mb-4"> <label for="code">Enter Code</label> <input type="text" class="form-control" id="code" /> </div> <div class="md-form mb-4"> <label for="nobales">Enter No Of Bales</label> <input type="number" min="1" class="form-control" id="nobales" /> </div> </div> <div class="modal-footer d-flex justify-content-center"> <button class="btn" id="save">Save</button> </div> </div> </div> </div> </form> </body> </html>
Another page:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function printDom(){ for (var i = 2; i <=<%= Request.QueryString["nobales"].ToString() %>; i++) { var parent = document.getElementById('divBig'); var newChild = '<div class="page-break"></div> <br /><br /><div class="printdiv">'+'<div style="margin-top:80px;"><p>' + '<%= Request.QueryString["containerNo"].ToString() %> ' + '</p><p>' + '<%= Request.QueryString["code"].ToString() %>' + '</p><p style="float: right; margin-top: 100px;">'+i+' of ' + '<%= Request.QueryString["nobales"].ToString() %>' + '</p></div></div>'; parent.insertAdjacentHTML('beforeend', newChild); } var printContents = document.getElementById("divBig").innerHTML; var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; } </script> <style type="text/css"> .printdiv, .printdiv1 { width: 300px; height: 300px; margin: 0 auto; border: 1px solid black; text-align: center; } .printdiv { display: none; } @page { size: auto; margin: 0; } @media all { .page-break { display: none; } } @media print { .page-break { display: block; page-break-before: always; } .printdiv { display: block; } } </style> </head> <body> <form id="form1" runat="server"> <button id="print" onclick="printDom()">Print</button> <div id="divBig"> <br /><br /> <div class="printdiv1" id="printdiv" style=""> <div style="margin-top: 80px;"> <p><%= Request.QueryString["containerNo"].ToString() %></p> <p><%= Request.QueryString["code"].ToString() %></p> <p style="float: right; margin-top: 100px;">1 to <%= Request.QueryString["nobales"].ToString() %></p> </div> </div> </div> </form> </body> </html>The result of work demo:
Best Regards,
YongQing.
Friday, August 2, 2019 8:35 AM -
User-367318540 posted
Thanks alot YongQing,
Do you want to embed the button of webform in the crystal report to print? Please tell us more detailed about it.
Yes i want embed the button of weform.....second thing is that how to set print page size,,,,,
Note: i have to insert data into database Number of Pages qty and Textboxes values in sql
Friday, August 2, 2019 9:03 AM -
User665608656 posted
Hi akhterr,
Do you want to embed the button of webform in the crystal report to print? Please tell us more detailed about it.For this issue, I have found a tutorial that is very similar to it. You can refer to this link : Print Crystal Report at Client Side Printer in ASP.NET
Hope this will help you.
second thing is that how to set print page sizeTo solve this , you can modify the CSS style according to your requirement for paper size. You can refer to:
Possible to force printer setup (paper size) in javascript?
Best Regards,
YongQing.
Monday, August 5, 2019 9:51 AM -
User-367318540 posted
Hi Yogqing Yu,
I am currently printing one label on a page ,,,,it working fine...but i want that method or technique ,which i found in that video...that is to print one text multiple label.....
which i do not ,how will get it done?
Monday, August 5, 2019 10:41 AM -
User665608656 posted
Hi akhterr,
that is to print one text multiple label.....For this issue, I have given you a comprehensive code in my first reply, which includes this function: https://forums.asp.net/post/6273039.aspx
If I misunderstand you, I hope you can describe your requirements in detail, or provide us with your current detailed code, which will help us solve your issue more easily.
Best Regards,
YongQing.
Tuesday, August 6, 2019 1:06 AM -
User-367318540 posted
here is my web form html... here i want to user input No of print of label...Currently i am calling data from database then print on crystal report after inserting record.
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="BBInputForm.aspx.cs" Inherits="Appprd.BBInputForm" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <%--<html xmlns="http://www.w3.org/1999/xhtml">--%> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script> <script type="text/javascript"> $(function () { $(".js-example-placeholder-single").select2({ placeholder: "Select", allowClear: true }); }); </script> <style type="text/css"> .auto-style1 { width: 100%; } .auto-style2 { height: 23px; } .auto-style3 { height: 26px; } .js-example-placeholder-single {} </style> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } td { cursor: pointer; } .hover_row { background-color: #ffd800; } .auto-style1 { width: 100%; } .auto-style2 { width: 250px; text-align: right; } .auto-style3 { width: 460px; } .auto-style4 { width: 250px; text-align: right; height: 30px; } .auto-style5 { width: 451px; height: 30px; } .auto-style6 { height: 30px; } .auto-style7 { width: 250px; text-align: right; height: 27px; background-color: #C0C0C0; } .auto-style8 { width: 451px; height: 27px; background-color: #C0C0C0; } .auto-style9 { height: 27px; background-color: #C0C0C0; } .auto-style10 { height: 23px; } .auto-style11 { width: 250px; text-align: right; height: 29px; background-color: #C0C0C0; } .auto-style12 { width: 451px; height: 29px; background-color: #C0C0C0; } .auto-style13 { height: 29px; background-color: #C0C0C0; } .auto-style14 { width: 250px; text-align: right; height: 23px; background-color: #C0C0C0; } .auto-style15 { width: 451px; height: 23px; background-color: #C0C0C0; } .auto-style16 { font-size: xx-large; background-color: #FFFF99; } .auto-style18 { width: 451px; background-color: #C0C0C0; } .auto-style19 { width: 250px; text-align: right; background-color: #C0C0C0; } .auto-style22 { background-color: #C0C0C0; } .auto-style23 { height: 23px; background-color: #C0C0C0; } .auto-style24 { height: 23px; width: 5px; } .auto-style25 { width: 5px; } </style> <%-- <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server">--%> <div> <script type = "text/javascript"> var ddlText, ddlValue, ddl, lblMesg; function CacheItems() { ddlText = new Array(); ddlValue = new Array(); ddl = document.getElementById("<%=ddlBbitem.ClientID %>"); lblMesg = document.getElementById("<%=lblMessage.ClientID%>"); for (var i = 0; i < ddl.options.length; i++) { ddlText[ddlText.length] = ddl.options[i].text; ddlValue[ddlValue.length] = ddl.options[i].value; } } window.onload = CacheItems; function FilterItems(value) { ddl.options.length = 0; for (var i = 0; i < ddlText.length; i++) { if (ddlText[i].toLowerCase().indexOf(value) != -1) { AddItem(ddlText[i], ddlValue[i]); } } lblMesg.innerHTML = ddl.options.length + " items found."; if (ddl.options.length == 0) { AddItem("No items found.", ""); } } function AddItem(text, value) { var opt = document.createElement("option"); opt.text = text; opt.value = value; ddl.options.add(opt); } </script> <table class="auto-style1"> <tr> <td class="auto-style4"></td> <td class="auto-style5"> <h1 class="auto-style16">Big Bale Production</h1> </td> <td class="auto-style6">Entry Date :<asp:TextBox ID="txtbpentrydate" runat="server" ReadOnly="True"></asp:TextBox> </td> </tr> <tr> <td class="auto-style19"> <asp:DropDownList ID="DDLEmpID" runat="server"> </asp:DropDownList> </td> <td class="auto-style18"> </td> <td class="auto-style22"> </td> </tr> <tr> <td class="auto-style7"> </td> <td class="auto-style8"> </td> <td class="auto-style9"></td> </tr> <tr> <td class="auto-style11">Item Description</td> <td class="auto-style12"> <asp:DropDownList ID="ddlBbitem" runat="server" CssClass="form-control js-example-placeholder-single" ToolTip="Select " Height="16px" OnSelectedIndexChanged="ddpitem_SelectedIndexChanged" AutoPostBack="True"> </asp:DropDownList> <asp:TextBox ID="txtsear" runat="server" onkeyup = "FilterItems(this.value)" Width="90px"></asp:TextBox> <asp:Label ID="lblMessage" runat="server" Text="lblMessage"></asp:Label> </td> <td class="auto-style13"></td> </tr> <tr> <td class="auto-style14">Prd Qty : </td> <td class="auto-style15"> <asp:Label ID="opbbqty" runat="server" Text="Label"></asp:Label> </td> <td class="auto-style23">Last Bale Number:<asp:Label ID="lbbno" runat="server" Text="Label" Font-Bold="True" Font-Size="Larger"></asp:Label> </td> </tr> <tr> <td class="auto-style14">Catagory : </td> <td class="auto-style15"> <asp:DropDownList Enabled="false" ID="DDLBBCID" runat="server" > </asp:DropDownList> Section : <asp:DropDownList ID="DDLBBsec" Enabled="false" runat="server" AppendDataBoundItems="true"> <asp:ListItem Value="" Text="Select Section"></asp:ListItem> </asp:DropDownList> </td> <td class="auto-style23"> </td> </tr> <tr> <td class="auto-style19">Weight</td> <td class="auto-style18"> <asp:TextBox ID="prdbqty" runat="server" ReadOnly="false"></asp:TextBox> </td> <td class="auto-style22"> </td> </tr> <tr> <td class="auto-style2"> </td> <td class="auto-style3"> <asp:Button ID="tbsv" runat="server" Text="save" OnClick="tbsv_Click" Height="25px" Width="66px" /> </td> <td> </td> </tr> </table> </div> <table class="auto-style1"> <tr> <td class="auto-style24"></td> <td class="auto-style10"> </td> <td class="auto-style10"></td> </tr> <tr> <td class="auto-style25"> </td> <td> </td> <td> </td> </tr> <tr> <td class="auto-style25"> </td> <td> </td> <td> </td> </tr> </table> <%-- </form> </body>--%> </asp:Content>
Here is my C# code ... which is inserting data into db and redirect last Record ID on another page ...which is highlighted in yellow
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.IO; using System.Globalization; using Microsoft.Reporting.WebForms; namespace Appprd { public partial class BBInputForm : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=.SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;"); QryMgmt dm = new QryMgmt(); protected void Page_Load(object sender, EventArgs e) { if ( Session["EmpID"]==null) { Response.Redirect("LogingForm.aspx"); } if (!Page.IsPostBack) { //this.BindGrid(); // txtpno.Text = String.Empty; lastbaleno(); loaditemBB(); loadSection(); loadcatrgory(); txtbpentrydate.Text = DateTime.Now.ToString(); opbbqty.Text = "1"; int id = Convert.ToInt16(Session["EmpID"]); string sessionId = Session.SessionID; } } private void loadcatrgory() { SqlConnection con = new SqlConnection("Data Source=.SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;"); con.Open(); SqlDataAdapter adpbb = new SqlDataAdapter("select * from Catagory", con); DataSet dsbb = new DataSet(); adpbb.Fill(dsbb); DDLBBCID.DataSource = dsbb.Tables[0]; DDLBBCID.DataTextField = "CName"; DDLBBCID.DataValueField = "CID"; DDLBBCID.DataBind(); // DDSec.Items.Insert(0, new ListItem("Select Section", "0")); con.Close(); con.Dispose(); } private void loadSection() { SqlConnection con = new SqlConnection("Data Source=.SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;"); con.Open(); SqlDataAdapter adpbas = new SqlDataAdapter("select * from Sections", con); DataSet dsbas = new DataSet(); adpbas.Fill(dsbas); DDLBBsec.DataSource = dsbas.Tables[0]; DDLBBsec.DataTextField = "Secnam"; DDLBBsec.DataValueField = "SecID"; DDLBBsec.DataBind(); // DDSec.Items.Insert(0, new ListItem("Select Section", "0")); con.Close(); con.Dispose(); } private void loaditemBB() { con = new SqlConnection("Data Source=.SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;"); con.Open(); SqlDataAdapter adpbp = new SqlDataAdapter("select * from ItemMasterFile where TID='2'", con); DataSet dsbp = new DataSet(); adpbp.Fill(dsbp); ddlBbitem.DataSource = dsbp.Tables[0]; ddlBbitem.DataTextField = "Descriptionitem"; ddlBbitem.DataValueField = "Codeitem"; ddlBbitem.DataBind(); ddlBbitem.Items.Insert(0, new ListItem("Select Item Name", "")); con.Close(); con.Dispose(); } private void lastbaleno() { con.Open(); SqlCommand cmdpbiw = new SqlCommand("SELECT MAX(BID) AS Expr1 FROM Bigbalprd"); cmdpbiw.Connection = con; cmdpbiw.CommandType = CommandType.Text; SqlDataAdapter dapbdw = new SqlDataAdapter(cmdpbiw); DataTable dtpbdw = new DataTable(); dapbdw.Fill(dtpbdw); lbbno.Text = dtpbdw.Rows[0][0].ToString(); lbbno.DataBind(); con.Close(); con.Dispose(); } protected void tbsv_Click(object sender, EventArgs e) { if (ddlBbitem.SelectedValue == "") { Response.Write("<script>alert('Please Select Item Name')</script>"); } else if (prdbqty.Text == "") { Response.Write("<script>alert('Please Input Weight')</script>"); } else { con.Open(); SqlCommand cmd = new SqlCommand("spInsertbigbale", con); cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@RollNo", TextBox4.Text.Trim()); cmd.Parameters.AddWithValue("@Codeitem", ddlBbitem.SelectedValue); cmd.Parameters.AddWithValue("@Bweight", prdbqty.Text.Trim()); cmd.Parameters.AddWithValue("@Bpqty", opbbqty.Text.Trim()); cmd.Parameters.AddWithValue("@CID", DDLBBCID.SelectedValue); cmd.Parameters.AddWithValue("@SecID", DDLBBsec.SelectedValue); cmd.Parameters.AddWithValue("@EmpID", Session["EmpID"].ToString().Trim()); cmd.Parameters.AddWithValue("@EntryDate", txtbpentrydate.Text); cmd.Parameters.Add("@BID", SqlDbType.Int); cmd.Parameters["@BID"].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); int ResultValue = Convert.ToInt32(cmd.Parameters["@BID"].Value); if (ResultValue > 1) { Response.Redirect("BBPView.aspx?BID=" + ResultValue + ""); } else { Response.Write("<script>alert('Record Not save')</script>"); } con.Close(); con.Dispose(); } } protected void ddpitem_SelectedIndexChanged(object sender, EventArgs e) { String strQuery = "select CID,SecID From itemMasterFile where" + " itemMasterFile.CodeItem = @CodeItem"; // SqlConnection con = new SqlConnection(); SqlCommand cmde = new SqlCommand(); cmde.Parameters.AddWithValue("@CodeItem", ddlBbitem.SelectedItem.Value); cmde.CommandType = CommandType.Text; cmde.CommandText = strQuery; cmde.Connection = con; try { con.Open(); SqlDataReader sdr = cmde.ExecuteReader(); while (sdr.Read()) { DDLBBCID.SelectedValue = sdr[0].ToString(); DDLBBsec.SelectedValue = sdr[1].ToString(); } } catch (Exception ex) { throw ex; } finally { con.Close(); con.Dispose(); } } } }
on BBPView.aspx i drop crystal report viewer
here is html
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="BBPView.aspx.cs" Inherits="Appprd.BBPView" %> <%@ Register Assembly="CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <CR:CrystalReportViewer ID="BBPViewer" runat="server" AutoDataBind="true" /> </asp:Content>
and it c# code.... highlighted green line below ( CRBigbalprnt.rpt) i attached crystal report viewer where data is retrieved from table..
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.IO; using System.Globalization; using Microsoft.Reporting.WebForms; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace Appprd { public partial class BBPView : System.Web.UI.Page { SqlConnection con = new SqlConnection(); ReportDocument rpt = new ReportDocument(); protected void Page_Load(object sender, EventArgs e) { //if (!IsPostBack) { rpt.Dispose(); rpt.Close(); loadReport(); } } private void loadReport() { rpt.Dispose(); rpt.Close(); con = new SqlConnection("Data Source = ATLANTIC\\SQLEXPRESS; Integrated Security = SSPI; Initial Catalog = SilverProduction; MultipleActiveResultSets = True; "); try { con.Open(); SqlCommand cmd = new SqlCommand("sp_bigbaleprint", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BID", Request.QueryString["BID"]); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); //SqlDataAdapter adp = new SqlDataAdapter("select prdno,orderno,Codeitem,prdqty from probale", con); //DataSet ds = new DataSet(); //adp.Fill(ds); // var dialog = new PrintDialog(); { //ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath("~/CRBigbalprnt.rpt")); rpt.SetDataSource(ds.Tables["Table"]); BBPViewer.ReportSource = rpt; rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, false, "Bigbalprd"); } } catch (Exception ex) { } } protected void CRBigview_Unload(object sender, EventArgs e) { if (rpt != null) { rpt.Close(); rpt.Dispose(); } rpt.Close(); } } }
Please if you have any query please ask.....i am stuck
Tuesday, August 6, 2019 5:10 AM