We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Need help in binding Datasource to PDFGrid

Hi,

Bear with me as I am new to this..
I need to print Gridview (ASP.net) contents into a PDF page.
When binding my DataSource to the PdfGrid, it throws the following Exception:
StackTrace
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Pdf.Grid.PdfGrid.PopulateHeader()
at Syncfusion.Pdf.Grid.PdfGrid.SetDataSource()
at Syncfusion.Pdf.Grid.PdfGrid.set_DataSource(Object value)

Any help much appreciated..
Code snippet::
public void PrintToPdf()
{
PdfDocument doc = new PdfDocument();

//Add a page

PdfPage page = doc.Pages.Add();

//Create Pdf graphics for the page

PdfGraphics g = page.Graphics;

//Create a solid brush

PdfBrush brush = new PdfSolidBrush(Color.Black);

float fontSize = 20f;

//Set the font

PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize);

DAL.emsDAL dal = new DAL.emsDAL();
try
{
PdfGrid grid = new PdfGrid();

List result = dal.getResults(1, 1, 1, new DateTime(2010, 7, 1), new DateTime(2010, 7, 5));//dal.getResults(plantID, chimID, pollID, dateFrom, dateTo);

// DataSource shows a count of 120.

grid.DataSource = result;// Exception is thrown here!!


grid.Draw(page.Graphics, PointF.Empty, 100);

}
catch (Exception ex)
{ }


//Stream the output to the browser.

if (this.CheckBox1.Checked)
{

doc.Save("Sample.pdf", Response, HttpReadType.Open);

}

else
{

doc.Save("Sample.pdf", Response, HttpReadType.Save);

}


}
//////////////////

Thanks for your time.

1 Reply

PJ Pravin Joshua D Syncfusion Team July 8, 2010 10:17 AM UTC

Hi Adrain,

Thank you for using Essential PDF.

It is not possible to pass a list as datasource for the PdfGrid.The datasource for a PdfGrid can be an array (two-dimensional, one-dimensional or nested), a DataTable, DataColumn, DataView or DataSet.

Please refer to the documentation in the link below, for more details.

Documentation:

http://help.syncfusion.com/ug_82/Reporting_PDF/GridCreation.html

Let us know if you have any questions.

Regards,
Pravin.


Loader.
Live Chat Icon For mobile
Up arrow icon