Active Report how to page break when dynamically add control to the page during report Start Event?

2.1k views Asked by At

I am adding table base on my database and dynamically create the table from code behind. The problem is I want a page break after the table is created.

Since I cannot add control on detail event, I can only page break once which is at report start. Hence, is there any possible way to constantly adding page break ?

Here is my structure

private void Report_ReportStart(object sender, EventArgs e)
{
    System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(rptFnc.GetConnStr());
    cnn.Open();

    using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
    {
        string userID = GlobalFnc.GlobalSetting.UserID;
        cmd.Connection = cnn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "exec storedprocedure"

        using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd))
        {
            da.Fill(dtWorkplaceID);
        }
    }

    cnn.Close();

    try
    {
        if (dtData.Rows.Count > 0)
        {
            foreach (DataRow drData in dtData.Rows)
            {
                CreateTable(drData ["Data"].ToString(), decimal.Parse(drData["Data"].ToString()));
                detail.NewPage = NewPage.After;
            }
        }
    }
}

public void CreateTable(string Data,decimal data2)
{
    Label Data = new Label();
    Data.Text = data;
    Data.Height = 0.25F;
    Data.Width = 1.0F;
    Data.Location = new PointF(0F,0F);
    Data.border.style = BorderLineStyle.Solid;
    detail.control.add(data);

    Continue ........... To Create a Table
}

This is the sample what I am trying to do. And I want to insert page break whenever a cycle of creating a table finish. It can be a new page or page break will be fine as long it goes to a new page after a cycle.

1

There are 1 answers

0
Mohita On

A suggestion for you would be to make use of PageBreak control after each 'for each' loop. This would add a page break after each table.

Hence, your code would be like :

if (dtData.Rows.Count > 0)
        {
            foreach (DataRow drData in dtData.Rows)
            {
                CreateTable(drData ["Data"].ToString(), decimal.Parse(drData["Data"].ToString()));
                //detail.NewPage = NewPage.After;
            }
           // Add a PageBreak control here.
        }`

Regards, Mohita