Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have use

C#
using Spire.Pdf;
using Spire.Pdf.Grid;
using Spire.Pdf.Graphics;
using Spire.Pdf.HtmlConverter;


now i want retrive grid-view data in
C#
PdfTextWidget textWidget = new PdfTextWidget(griddata, font, brush);


in above code griddata i had use , what i have to use there for retrive all data from gridview?

What I have tried:

string[] str = new string[gridtable.Rows.Count];
for (int i = 0; i < gridtable.Rows.Count; i++)
{

str[i] = gridtable.Rows[i].Cells[0].Value.ToString();

}
PdfTextWidget textWidget = new PdfTextWidget(str.ToString(), font, brush);
Posted
Updated 21-Dec-16 17:33pm
Comments
Sinisa Hajnal 15-Jun-16 4:50am    
What is the problem? Do you get an error? What type should griddata be? If just string, in what format? What do you expect to get from calling ToString on an array?
Kumbhani Bhavesh 15-Jun-16 4:57am    
i want print data in pdf file so i use PdfTextWidget textWidget = new PdfTextWidget(str.ToString(), font, brush);
now i get data in gridview but i want that all griddata in string array and can use it as PdfTextWidget textWidget = new PdfTextWidget(griddataHear, font, brush);

1 solution

by this code you will only get the first column of data grid.
C#
string[] str = new string[gridtable.Rows.Count];
 for (int i = 0; i < gridtable.Rows.Count; i++)
 {

 str[i] = gridtable.Rows[i].Cells[0].Value.ToString();

 }
 PdfTextWidget textWidget = new PdfTextWidget(str.ToString(), font, brush); 



to store datagrid data in string you need to store in multidimensional string array.
use below code to fetch all data from datagrid.

C#
string[,] str = new string[gridtable.Rows.Count,gridtable.Columns.Count];

for (int i = 0;i< gridtable.Rows.Count; i++)
 {
	for(int j=0;j<gridtable.Rows.Count; j++)
	{
 		str[i,j] = gridtable.Rows[i].Cells[j].Value.ToString();
	}	
 }


I haven't used 'PdfTextWidget' but ive used 'iTextsharp' DLL's to create PDF.
You can use the above same looping sequence to write data to PDF from multidimensional string array.
 
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