Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print the specific rows of the Gridview by storing the OrderID and ItemID concatenated together and adding them in an Arraylist.
Now I pass this ArrayList to a method in my DAL Class which returns a DataTable.

When I set the report.SetDataSource(dal.Print(printPage));
('where Print is a method that accepts the Arraylist printPage')

it only prints a blank report.

Here is the code I am doing upon the button click:
protected void Button1_Click(object sender, EventArgs e)
        DispatchablePowerItems_DAL dal = new DispatchablePowerItems_DAL();
        ArrayList printPage = new ArrayList();

        string constr = "Server=.; Database=SupplyCM; uid=sa; pwd=123";
        string query = "SELECT UserName, OrderID, ItemID, ItemName, Quantity, UnitPrice, Total FROM PowersDispatch";
        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        ReportDocument report = new ReportDocument();
        string reportFile = Server.MapPath("CrystalReportPower.rpt");
        int sum = 0;
        string driverName;
        foreach (GridViewRow row in GridView1.Rows)
            if (row.RowType == DataControlRowType.DataRow)
                if (TextBox1.Text == row.Cells[3].Text)
                    sum = sum + Convert.ToInt32(row.Cells[9].Text);
                    string orderId = row.Cells[4].Text; // To obtain OrderID
                    string itemId = row.Cells[5].Text; // to obtain ItemID
                    string orderIDitemID = orderId + "#" + itemId; // Concatenation of OrderID and ItemID
        TextBox2.Text = sum.ToString();

        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        report.PrintToPrinter(1, false, 0, 0);        

The following is the code I am doing in my DAL Class:

public DataTable Print(System.Collections.ArrayList PageList)
        string constr = "Server=.; Database=SupplyCM; uid=sa; pwd=123";
        string query = "SELECT UserName, OrderID, ItemID, ItemName, Quantity, UnitPrice, Total FROM PowersDispatch Order By UserName, OrderID";
        SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, con);
        SqlTransaction tr = null;

        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        DataTable table = new DataTable();


            tr = con.BeginTransaction();
            com.Transaction = tr;
            com.Parameters.Add("@OrderID", SqlDbType.NVarChar);
            com.Parameters.Add("@ItemID", SqlDbType.NVarChar);

            foreach (object item in PageList)
                string s = item.ToString();
                string[] tokens = s.Split(new char[] { '#' });

                string left = tokens[0];
                string right = tokens[1];

                com.Parameters["@OrderID"].Value = left;
                com.Parameters["@ItemID"].Value = right;
            return table;
        catch (Exception ex)
            throw ex;


1 solution

Check the Crystal report Event log file if any error there.

Ans try this trick for now.

PrintToPrinter printing a blank sheet of paper.[^]
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