Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Datalist to pdf [modified]

Datalist to pdf [modified]

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ferronrsmith
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • F ferronrsmith

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      F 1 Reply Last reply
      0
      • L Lost User

        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

        F Offline
        F Offline
        ferronrsmith
        wrote on last edited by
        #3

        tried using that code, it doesn't work

        Ferron

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups