导出网格 [英] export the grid

查看:158
本文介绍了导出网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在制作一个ASP.NET Web应用程序..
我的应用程序中只有一个网格
我也有一个导出按钮.
现在我想要当我单击导出按钮时,然后
的数据 网格应保存在.xls文件中..

我的代码是这样,可以成功运行,但是在运行时不起作用


hello I am making an ASP.NET web appplication..
I have one grid in my application
I also have an export button..
Now I wants that when I click on export button, then the data of the
grid should be save in .xls file..

My code is this, it bilds succed but at runtime it is not working


protected void BtnExport_Click(object sender, EventArgs e)
{
  Response.Clear();
  Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
  Response.Charset = "";
 Response.Cache.SetCacheability(HttpCacheability.NoCache);

    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(stringWrite.ToString());
  Response.End();
}



public override void VerifyRenderingInServerForm(Control control) 

{ 

  

}


它不起作用


Its not working

推荐答案

我不喜欢编写html并在Excel中显示html的技术.

我绝对希望使用普通的XLS格式导出数据.

可能正在使用:
使用MDAC和Oledb使用MS Excel(xls/xlsx) [ http://aspalliance.com/771 [ ^ ]
I dont like the technique of writing the html and show the html in Excel.

I would definitely prefer to use the normal XLS format to export data.

May be using this :
Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^]

If you still like this technique, use
http://aspalliance.com/771[^]


I dont like the technique of writing the html and show the html in Excel. 

I would definitely prefer to use the normal XLS format to export data.





我没听懂你说的话.

我尝试了您告诉的代码..它成功建立了,但是在运行时
它既不工作也不显示任何错误





I didn''t get that what u said..

I tried the code which u told.. it builds succed but at run time
it is not working neither showing any error


这篇关于导出网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆