Datagrid 2 Excel Problem

G

Guest

Hi friends...

I try my code in my development machine this work...

private void botonexcel_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{

Response.Clear();
Response.Buffer = true;
//Response.Charset = "UTF-8";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=export");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);
//this.ClearControls(this.grdresult);
this.grdresult.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}

private void ClearControls(Control control)
{
for (int i=control.Controls.Count -1; i>=0; i--)
{
ClearControls(control.Controls);
}
if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text =
(string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch
{

}
control.Parent.Controls.Remove(control);
}
else
if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text =
(string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}


but dont work in my client... the excel file save as HTML plz.... any idea????


GrG
 
Y

Yunus Emre ALPÖZEN

Are u using Windows 2003 IIS v6 with compression. If yes, this code doesn't
work. You had to disable compression in some way. For the compression, I
wrote my own compression code before windows 2003 has been anounced..

I have nearly the same code and it is running..
 
G

Guest

Yes Im using W2k3 IIS v6... Can u put ur code here? plzzzzz

Yunus Emre ALPÖZEN said:
Are u using Windows 2003 IIS v6 with compression. If yes, this code doesn't
work. You had to disable compression in some way. For the compression, I
wrote my own compression code before windows 2003 has been anounced..

I have nearly the same code and it is running..


--
Thanks,
Yunus Emre ALPÖZEN



Greg said:
Hi friends...

I try my code in my development machine this work...

private void botonexcel_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{

Response.Clear();
Response.Buffer = true;
//Response.Charset = "UTF-8";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=export");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);
//this.ClearControls(this.grdresult);
this.grdresult.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}

private void ClearControls(Control control)
{
for (int i=control.Controls.Count -1; i>=0; i--)
{
ClearControls(control.Controls);
}
if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text =
(string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch
{

}
control.Parent.Controls.Remove(control);
}
else
if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text =
(string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}


but dont work in my client... the excel file save as HTML plz.... any
idea????


GrG

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top