Datagrid 2 Excel Problem

Discussion in 'ASP .Net' started by =?Utf-8?B?R3JlZw==?=, Dec 26, 2004.

  1. 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
     
    =?Utf-8?B?R3JlZw==?=, Dec 26, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Yunus Emre ALPÖZEN, Dec 27, 2004
    #2
    1. Advertising

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

    "Yunus Emre ALPÖZEN" wrote:

    > 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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
     
    =?Utf-8?B?R3JlZw==?=, Dec 27, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Excel _WorkBook vs. Excel.Workbook

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,649
    Steve C. Orr [MVP, MCSD]
    Sep 29, 2004
  2. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,526
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  3. Paul D. Fox

    Display a Datagrid & Export a Datagrid to Excel

    Paul D. Fox, Jul 21, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    227
    Elton Wang
    Jul 21, 2005
  4. fniles
    Replies:
    0
    Views:
    278
    fniles
    Apr 26, 2009
  5. Replies:
    1
    Views:
    833
Loading...

Share This Page