This is the code to export data from grid to xls. But the problem is when the grid has more than one page the file cant be exported.
Code:
YourDataGrid.Columns[0].Visible = false; //This hides the line where the ButtonCollumn is.
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
YourDataGrid.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
YourDataGrid.Columns[0].Visible = true;
Error:
Control 'UCClientes_YourDataGrid__ctl21__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control 'UCClientes_YourDataGrid__ctl21__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.
Source Error:
Line 138:
Line 139:
Line 140: Dt.RenderControl(oHtmlTextWriter);
Line 141:
Line 142:
|