Datalist to pdf [modified]
-
I am trying to convert datalist control to pdf. Are there any third party tool that can do this or any tutorials on how to accomplish this? I have been googling and trying stuff, but they do not work. Anyways, please help :) :) :)
Ferron
modified on Wednesday, July 1, 2009 4:48 PM
-
I am trying to convert datalist control to pdf. Are there any third party tool that can do this or any tutorials on how to accomplish this? I have been googling and trying stuff, but they do not work. Anyways, please help :) :) :)
Ferron
modified on Wednesday, July 1, 2009 4:48 PM
PDFSharp or you can try this code
//SQL Connection Settings -----------
public string strConn = ConfigurationManager.ConnectionStrings["BLAH-Here"].ConnectionString;
//-----------------------------------protected void Page_Load(object sender, EventArgs e)
{
//Grab the same data as the datagrid [report view] on the reporting page
//Then set the "ContentType" to "application/vnd.ms-excel" which will generate the .XSL file//---Retrieve the Report from SQL, drop into DataSet, then Bind() it to a DataGrid
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("EXEC [dbo].[spStatReport] @CompanyID=" + Session["CompanyID"] + ", @StatReportID=" + Request.QueryString["ReportID"].ToString() + ", @StartDate='" + Request.QueryString["StartDate"].Replace("-", "/").ToString() + "', @EndDate='" + Request.QueryString["EndDate"].Replace("-", "/").ToString() + "';", conn);
cmd1.SelectCommand.CommandType = CommandType.Text;
DataSet dsReports = new DataSet("tblReporting");
cmd1.Fill(dsReports);
conn.Close();DataGrid dtaFinal = new DataGrid();
dtaFinal.DataSource = dsReports.Tables[0];
dtaFinal.DataBind();dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White;
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White;
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue;//---Create the File---------
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();//---For PDF uncomment the following lines----------
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");//---For MS Excel uncomment the following lines----------
//Response.ContentType = "application/vnd.ms-excel";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");//---For MS Word uncomment the following lines----------
//Response.ContentType = "application/vnd.word";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");//---For CSV uncomment the following lines----------
//Response.ContentType = "text/csv";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.csv");//---For TXT uncomment the following lines----------
//Response.ContentType = "text/plain";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.txt");EnableViewStat
-
PDFSharp or you can try this code
//SQL Connection Settings -----------
public string strConn = ConfigurationManager.ConnectionStrings["BLAH-Here"].ConnectionString;
//-----------------------------------protected void Page_Load(object sender, EventArgs e)
{
//Grab the same data as the datagrid [report view] on the reporting page
//Then set the "ContentType" to "application/vnd.ms-excel" which will generate the .XSL file//---Retrieve the Report from SQL, drop into DataSet, then Bind() it to a DataGrid
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("EXEC [dbo].[spStatReport] @CompanyID=" + Session["CompanyID"] + ", @StatReportID=" + Request.QueryString["ReportID"].ToString() + ", @StartDate='" + Request.QueryString["StartDate"].Replace("-", "/").ToString() + "', @EndDate='" + Request.QueryString["EndDate"].Replace("-", "/").ToString() + "';", conn);
cmd1.SelectCommand.CommandType = CommandType.Text;
DataSet dsReports = new DataSet("tblReporting");
cmd1.Fill(dsReports);
conn.Close();DataGrid dtaFinal = new DataGrid();
dtaFinal.DataSource = dsReports.Tables[0];
dtaFinal.DataBind();dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White;
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White;
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue;//---Create the File---------
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();//---For PDF uncomment the following lines----------
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");//---For MS Excel uncomment the following lines----------
//Response.ContentType = "application/vnd.ms-excel";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");//---For MS Word uncomment the following lines----------
//Response.ContentType = "application/vnd.word";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");//---For CSV uncomment the following lines----------
//Response.ContentType = "text/csv";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.csv");//---For TXT uncomment the following lines----------
//Response.ContentType = "text/plain";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.txt");EnableViewStat
tried using that code, it doesn't work
Ferron