moving code from presentation to a Class Library
This piece of code is working well when it is in code behind an aspx page. Baicaly, I pull data from DB, populate a Gridview, then click a button to export the data. .  Here is the issue when moving the code to class library
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient; // sqlconnection, sqlcommand, dataset, datatable
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Collections;
using System.Text;< ...

Go to the complete details ...