Click here to Skip to main content
15,887,355 members
Home / Discussions / C#
   

C#

 
GeneralRe: about the usinhg Visual Studio 2010 beta 1 Pin
Pete O'Hanlon1-Jul-09 11:15
mvePete O'Hanlon1-Jul-09 11:15 
GeneralRe: about the usinhg Visual Studio 2010 beta 1 Pin
Mycroft Holmes1-Jul-09 21:33
professionalMycroft Holmes1-Jul-09 21:33 
GeneralRe: about the usinhg Visual Studio 2010 beta 1 Pin
Pete O'Hanlon1-Jul-09 22:07
mvePete O'Hanlon1-Jul-09 22:07 
GeneralRe: about the usinhg Visual Studio 2010 beta 1 Pin
Mycroft Holmes1-Jul-09 22:45
professionalMycroft Holmes1-Jul-09 22:45 
AnswerRe: about the usinhg Visual Studio 2010 beta 1 Pin
Vikram A Punathambekar1-Jul-09 19:55
Vikram A Punathambekar1-Jul-09 19:55 
AnswerRe: about abusing Visual Studio 2010 beta 1 Pin
OriginalGriff1-Jul-09 23:28
mveOriginalGriff1-Jul-09 23:28 
QuestionDatalist to pdf [modified] Pin
ferronrsmith1-Jul-09 10:12
ferronrsmith1-Jul-09 10:12 
AnswerRe: Datalist to pdf Pin
I Believe In GOD1-Jul-09 11:00
I Believe In GOD1-Jul-09 11:00 
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");


EnableViewState = false;

StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

//---Renders the DataGrid and then dumps it into the HtmlTextWriter Control
dtaFinal.RenderControl(hw);

//---Utilize the Response Object to write the StringWriter to the page
Response.Write(sw.ToString());
Response.Flush();
Response.Close();
Response.End();
}


I know nothing , I know nothing ...

GeneralRe: Datalist to pdf Pin
ferronrsmith1-Jul-09 12:26
ferronrsmith1-Jul-09 12:26 
QuestionDocument Viewer control Pin
CoLeichty1-Jul-09 8:26
CoLeichty1-Jul-09 8:26 
AnswerRe: Document Viewer control Pin
Luc Pattyn1-Jul-09 9:13
sitebuilderLuc Pattyn1-Jul-09 9:13 
QuestionAForge.net writer.Open problem Pin
tvbarnard1-Jul-09 7:59
tvbarnard1-Jul-09 7:59 
AnswerRe: AForge.net writer.Open problem Pin
tvbarnard1-Jul-09 8:07
tvbarnard1-Jul-09 8:07 
GeneralRe: AForge.net writer.Open problem Pin
Luc Pattyn1-Jul-09 8:24
sitebuilderLuc Pattyn1-Jul-09 8:24 
GeneralRe: AForge.net writer.Open problem Pin
tvbarnard1-Jul-09 8:52
tvbarnard1-Jul-09 8:52 
Questionhow to click a link in axwebbrowser Pin
T_Teef1-Jul-09 7:31
T_Teef1-Jul-09 7:31 
AnswerRe: how to click a link in axwebbrowser Pin
dan!sh 1-Jul-09 7:56
professional dan!sh 1-Jul-09 7:56 
QuestionRe: how to click a link in axwebbrowser Pin
T_Teef1-Jul-09 8:00
T_Teef1-Jul-09 8:00 
QuestionGraphicsPath.AddString vs Graphics.MeasureString Pin
nryk1-Jul-09 7:25
nryk1-Jul-09 7:25 
AnswerRe: GraphicsPath.AddString vs Graphics.MeasureString Pin
I Believe In GOD1-Jul-09 10:54
I Believe In GOD1-Jul-09 10:54 
Questionwindows login with own application..... Pin
S K Y1-Jul-09 5:50
S K Y1-Jul-09 5:50 
AnswerRe: windows login with own application..... Pin
DoctorMick1-Jul-09 6:05
DoctorMick1-Jul-09 6:05 
GeneralRe: windows login with own application..... Pin
S K Y1-Jul-09 8:19
S K Y1-Jul-09 8:19 
GeneralRe: windows login with own application..... Pin
Dave Kreskowiak1-Jul-09 8:55
mveDave Kreskowiak1-Jul-09 8:55 
GeneralRe: windows login with own application..... Pin
Christian Graus1-Jul-09 12:36
protectorChristian Graus1-Jul-09 12:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.