exporting gridview data into excel, i got this error. Help~
-
I tried to export gridview info to excel. I got this error. Control 'grdLIST' of type 'GridView' must be placed inside a form tag with runat=server. This my gridview design. <asp:GridView ID="grdLIST" runat="server" Visible="False"> </asp:GridView> I didn't setup fields, because field name is changing due to date term. This is aspx codeing protected void cmdEXCEL_Click(object sender, EventArgs e) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=CadilacReport.xls"); Response.Charset = string.Empty; Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); if (grdLIST.HeaderRow != null && grdLIST.HeaderRow.Cells != null) { for (int ct = 0; ct < grdLIST.HeaderRow.Cells.Count; ct++) { string headerText = grdLIST.HeaderRow.Cells[ct].Text; if (grdLIST.HeaderRow.Cells[ct].HasControls()) { if (grdLIST.HeaderRow.Cells[ct].Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataCountrlLinkButton") { headerText = ((LinkButton)grdLIST.HeaderRow.Cells[ct].Controls[0]).Text; } grdLIST.HeaderRow.Cells[ct].Controls.Clear(); } grdLIST.HeaderRow.Cells[ct].Text = headerText; } } if (grdLIST.FooterRow != null) { grdLIST.FooterRow.Visible = false; } grdLIST.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } at grdLIST.RenderControl(htmlWrite);, I got that error. How can I solve it? Please help.
-
I tried to export gridview info to excel. I got this error. Control 'grdLIST' of type 'GridView' must be placed inside a form tag with runat=server. This my gridview design. <asp:GridView ID="grdLIST" runat="server" Visible="False"> </asp:GridView> I didn't setup fields, because field name is changing due to date term. This is aspx codeing protected void cmdEXCEL_Click(object sender, EventArgs e) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=CadilacReport.xls"); Response.Charset = string.Empty; Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); if (grdLIST.HeaderRow != null && grdLIST.HeaderRow.Cells != null) { for (int ct = 0; ct < grdLIST.HeaderRow.Cells.Count; ct++) { string headerText = grdLIST.HeaderRow.Cells[ct].Text; if (grdLIST.HeaderRow.Cells[ct].HasControls()) { if (grdLIST.HeaderRow.Cells[ct].Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataCountrlLinkButton") { headerText = ((LinkButton)grdLIST.HeaderRow.Cells[ct].Controls[0]).Text; } grdLIST.HeaderRow.Cells[ct].Controls.Clear(); } grdLIST.HeaderRow.Cells[ct].Text = headerText; } } if (grdLIST.FooterRow != null) { grdLIST.FooterRow.Visible = false; } grdLIST.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } at grdLIST.RenderControl(htmlWrite);, I got that error. How can I solve it? Please help.
-
Hi, If you look at your source code of your aspx page, you might be missing the following tag below the body tag.
(Your grid declaration should be in here)
Hope this solves your problem. Regards, Elizma