Click here to Skip to main content
15,891,925 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to print all the web pages which are generated by the foreach loop. The below code prints only web page.

C#
Here is my complete code:

  private void LastSolution()
        {
            StringBuilder sb = new StringBuilder();


            List<PrintInfo> prints = ExcelData.GetDataFromExcel();
            foreach (var print in prints)
            {
                lblCertificate.Text = print.Certificate;
                lblAddress.Text = print.Address;
                lblBrand.Text = print.Brand;
                lblFrom.Text = print.FromDate;
                lblMobile.Text = print.Mobile;
                lblName.Text = print.Name;
                lblProduct.Text = print.Product;
                lblScheme.Text = print.Schema;
                lblSNo.Text = print.Sno;  
                lblTo.Text = print.ToDate;
                ///Write Print Code Here within Loop 
             ClientScript.RegisterClientScriptBlock(this.GetType(), "key","window.print()", true);





// Method body
        public static List<PrintInfo> GetDataFromExcel()
        {

            OleDbConnection oleconn = new OleDbConnection();
            OleDbCommand olecmd = new OleDbCommand();

            oleconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\ADMIN\\Desktop\\tryexcel.xlsx;Extended properties='Excel 12.0 Xml;HDR=YES;'";
            olecmd.CommandText = "select [c_firstname],[c_address],[c_mobilephone],[c_amctype],[c_fcrno],[c_product1],[c_band1],[c_slno1],[c_doa],[c_eoa] from [Sheet1$]";

            olecmd.Connection = oleconn;
            oleconn.Open();
            OleDbDataReader reader = olecmd.ExecuteReader();
            List<PrintInfo> prints = new List<PrintInfo>();
            PrintInfo print = null;
            while (reader.Read())
            {
                print = new PrintInfo();
                print.Certificate = reader.GetValue(4).ToString();
                print.Schema = reader.GetValue(3).ToString();
                print.Name = reader.GetValue(0).ToString();
                print.Address = reader.GetValue(1).ToString();
                print.Mobile = reader.GetValue(2).ToString();
                print.Product = reader.GetValue(5).ToString();
                print.Brand = reader.GetValue(6).ToString();
                print.Sno = reader.GetValue(7).ToString();
                print.FromDate = reader.GetValue(8).ToString();
                print.ToDate = reader.GetValue(9).ToString();

                prints.Add(print);
            }

            return prints;
        }
    

// Calling method here

private void LastSolution()
        {
            StringBuilder sb = new StringBuilder();


            List<PrintInfo> prints = ExcelData.GetDataFromExcel();
            foreach (var print in prints)
            {
                lblCertificate.Text = print.Certificate;
                lblAddress.Text = print.Address;
                lblBrand.Text = print.Brand;
                lblFrom.Text = print.FromDate;
                lblMobile.Text = print.Mobile;
                lblName.Text = print.Name;
                lblProduct.Text = print.Product;
                lblScheme.Text = print.Schema;
                lblSNo.Text = print.Sno;  
                lblTo.Text = print.ToDate;
                ///Write Print Code Here within Loop 
             ClientScript.RegisterClientScriptBlock(this.GetType(), "key","window.print()", true);
Posted
Updated 25-Jun-13 21:00pm
v2

1 solution

You don't show complete code which should show how you do it, but apparently, you are not doing anything for printing inside the loop.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900