I want to create a telerik report bearing the contents coming from a dataset. The report is to be created at runtime as the number of rows and columns of the dataset may vary depending on the stored procedure fired. I want to display the header on each and every page after exporting report to PDF. For displaying the header, I have created a function named "DisplayHeader()". I have currently displayed the header for the report in the detail section (and not in the header section) because the report was not displaying all the column headers on one line. I have pasted the code below :
public Report_PDF()
{
/// <summary>
/// Required for telerik Reporting designer support
/// </summary>
InitializeComponent();
DBUtilReport db = new DBUtilReport(Connectionstring);
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "select * FROM Tablename";
db.FillDataSet(cmd, ref ds);
Unit a = new Unit(100, UnitType.Pixel);
Unit b = new Unit(100, UnitType.Pixel);
Unit m = new Unit(10, UnitType.Pixel);
Unit n = new Unit(40, UnitType.Pixel);
int cols = ds.Tables[0].Columns.Count;
int paperWidth = 297;
int width = paperWidth / cols;
Unit TxtBoxWidth = new Unit(width, UnitType.Pixel)+n;
Unit k1 = new Unit(5.0, UnitType.Pixel);
DisplayHeader(m,k1,a,ds);
m = m + n + m;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Unit k = new Unit(10.0, UnitType.Pixel);
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
Telerik.Reporting.TextBox txtData = new Telerik.Reporting.TextBox();
txtData.Multiline = true;
txtData.TextWrap = true;
txtData.Style.TextAlign = HorizontalAlign.Left;
txtData.Style.VerticalAlign = VerticalAlign.Top;
txtData.Style.Font.Name = "Verdana";
txtData.Value = ds.Tables[0].Rows[i][j].ToString();
txtData.Height = new Unit(75, UnitType.Pixel);
txtData.Width = new Unit(100, UnitType.Pixel);
txtData.Left = k;
txtData.Top = m;
txtData.CanShrink = true;
this.detail.Items.Add(txtData);
k = k + a;
}
m = m + b;
}
// function for displaying the header
protected void DisplayHeader(Unit m,Unit k1,Unit a,DataSet ds)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
Telerik.Reporting.TextBox txtHeader = new Telerik.Reporting.TextBox();
txtHeader.Multiline = true;
txtHeader.TextWrap = true;
txtHeader.Style.TextAlign = HorizontalAlign.Left;
txtHeader.Style.VerticalAlign = VerticalAlign.Top;
txtHeader.Style.Font.Name = "Verdana";
txtHeader.Style.Font.Bold = true;
txtHeader.Value = ds.Tables[0].Columns[i].ColumnName.ToString();
txtHeader.Height = new Unit(75, UnitType.Pixel);
txtHeader.Width = new Unit(100, UnitType.Pixel);
txtHeader.Left = k1;
txtHeader.Top = m;
txtHeader.CanShrink = true;
this.detail.Items.Add(txtHeader);
k1 = k1 + a;
}
}