我正在做一个项目,我想下载 gridview 行数据,但它不适合我。这是我用于下载的代码:
string fileName = "chhattisgarhishafte" + DateTime.Now.ToString() + ".doc";
GridView1.DataSource = dtD;
GridView1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Charset = "";
Response.ContentType = "application/vnd.ms-word ";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.RenderBeginTag(hw);
GridView1.RenderControl(hw);
Response.Output.Write(sw.ToString());
GridView1.RenderEndTag(hw);
Response.Flush();
Response.End();
std 是存储 gridview 选定行的数据表。
错误是:
Control 'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.