tags:

views:

159

answers:

2

I first got an error usign the code below, explaining that "DataGridLinkButton' must be placed inside a form tag with runat=server."

Now I've tried setting AllowSorting to false, as well as removing the sort expression from each column, with the same error. Then I tried creating a new, plain, DataGrid, with the same data source, but now I get a blank page and FF doesn't recognise the content type properly any more. Please help.

Response.Clear();
base.Response.Buffer = true;
base.Response.ContentType = "application/vnd.ms-excel";
base.Response.AddHeader("Content-Disposition", "attachment;filename=file.xls");
base.Response.Charset = "";
this.EnableViewState = false;
StringWriter writer = new StringWriter();
HtmlTextWriter writer2 = new HtmlTextWriter(writer);
this.lblExport.RenderControl(writer2);
base.Response.Write(writer.ToString());
+1  A: 

Add the following empty method to your code. That should fix it.

public override void VerifyRenderingInServerForm(Control control)
    {
    }
Erikk Ross
A: 

public override void VerifyRenderingInServerForm(Control control) { }

more help look on
http://techdotnets.blogspot.com/