Tôi muốn covnvert dữ liệu GridView thành trang tính Excel.Làm thế nào để chuyển đổi dữ liệu GridView thành excel sheet trong asp .net với C# lang
Tôi đã viết đoạn code dưới đây, nhưng nó mang lại cho lỗi:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Avukat.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
Response.Write(stringWrite.ToString());
Response.End();
}
Lỗi:
Control 'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
nó cho thấy lỗi ở dòng này Response.AddHeader ("Content-Disposition ", tập tin đính kèm); –
Lỗi là gì? –
"Kiểm soát 'ctl00_ContentPlaceHolder1_GridView1' loại 'GridView' phải được đặt bên trong một thẻ biểu mẫu với runat = máy chủ" lỗi này tôi đã nhận nó. –