asp.net½«Ò³ÃæÖÐgridviewÖеÄÊý¾Ýµ¼Èëexcel±íÖÐ
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace AJAXEnabledWebApplication1
{
public partial class excelOutput : System.Web.UI.Page
{
DBClass db = new DBClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string strsql = "select * from TreeViewTemp where parentID=0";
DataTable dt = db.GetDataTable(strsql);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
OutPutExcel();
}
//´Ë´¦Òª×¢Òâ,Õâ¸öÖØÔØ·½·¨,Ò»¶¨ÒªÐ´,²»È»»á±¨ÀàÐÍ“GridView”µÄ¿Ø¼þ“GridView1”±ØÐë·ÅÔÚ¾ßÓÐ runat=server µÄ´°Ìå±ê¼ÇÄÚ
public override void VerifyRenderingInServerForm(Control control)
{
}
public void OutPutExcel()
{
//¶¨ÒåÎĵµÀàÐÍ¡¢×Ö·û±àÂë
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
//ÏÂÃæÕâÐкÜÖØÒª£¬ attachment ²ÎÊý±íʾ×÷Ϊ¸½¼þÏÂÔØ£¬Äú¿ÉÒÔ¸Ä³É onlineÔÚÏß´ò¿ª
//filename=FileFlow.xls Ö¸¶¨Êä³öÎļþµÄÃû³Æ£¬×¢ÒâÆäÀ©Õ¹ÃûºÍÖ¸¶¨ÎļþÀàÐÍÏà·û£¬¿ÉÒÔΪ£º.doc ¡¡¡¡ .xls ¡¡¡¡ .txt ¡¡¡¡.htm
Response.AppendHeader("Content-Disposition", "attachment;filename=FileFlow.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//Response.ContentTypeÖ¸¶¨ÎļþÀàÐÍ ¿ÉÒÔΪapplication/ms-excel¡¢application/ms-word¡¢application/ms-txt¡¢application/ms-html »òÆäËûä¯ÀÀÆ÷¿ÉÖ±½ÓÖ§³ÖÎĵµ
Ïà¹ØÎĵµ£º
ËÑË÷ÒýÇæÓÅ»¯¶ÔÈκÎÃæÏò¹«ÖÚµÄÍøÕ¾À´Ëµ¶¼·Ç³£ÖØÒª£¬ASP.net 4.0 Ϊ´Ë¾Í×öÁË´óÁ¿¸ÄÔì¡£ÕâЩ¸Ä½ø°üÀ¨ÈçÏ£º 301ÓÀ¾ÃÐÔÖض¨Ïò Ëæ×Åʱ¼äµÄǨÒÆ£¬ÍøÕ¾µÄһЩҳÃæµØÖ·»á·¢Éú±ä»¯£¬Õâ»áµ¼ÖÂËÑË÷ÒýÇæÊÕ¼µÄÁ´½ÓµØÖ·¡¢Óû§ÊղصĵØַʧЧ¡£Response.Redirect() ¾ÍÊǽâ¾öÕâ¸öÎÊÌâµÄ¡£µ«ÊÇResponse.Redirect ÓÐÒÔÏÂÎÊÌ⣺ Response. ......
1.//µ¯³ö¶Ô»°¿ò.µã»÷תÏòÖ¸¶¨Ò³Ãæ
Response.Write(" <script>window.alert('¸Ã»áԱûÓÐÌá½»ÉêÇë,ÇëÖØÐÂÌá½»£¡')
</script>");
Response.Write(" <script>window.location
='http://www.51aspx.com/bizpulic/upmeb.aspx' </script>");
2.//µ¯³ö¶Ô»°¿ ......
Request ÊôÐÔÌṩ¶Ô HttpRequest ÀàµÄÊôÐԺͷ½·¨µÄ±à³Ì·ÃÎÊ¡£ÓÉÓÚ ASP.NET Ò³°üº¬¶Ô System.Web ÃüÃû¿Õ¼ä£¨º¬ÓÐ HttpContext ÀࣩµÄĬÈÏÒýÓã¬Òò´ËÔÚ .aspx Ò³ÉÏ¿ÉÒÔÒýÓà HttpContext µÄ³ÉÔ±£¬¶ø²»ÐèÒª¶Ô HttpContext µÄÍêÈ«ÏÞ¶¨ÀàÒýÓá£ÀýÈ磬¿ÉֻʹÓà Request.Browser »ñÈ¡¿Í»§¶Ëä¯ÀÀÆ÷µÄ¹¦ÄÜ¡£µ«ÊÇ£¬Èç¹ûÒª´Ó ASP.NET ´ú ......
Beyond File | New Company: from Cheesy Sample to Social Platform Scott Hanselman in Lagoon L on Monday at 11:30 AM The web has changed and there's a new way of thinking about your applications. You can't just write some HTML and CSS anymore and expect to be the next Twitter. Hear h ......
2ÖÖ·½·¨
Ò»¡¢linkbuttonµÄµ¥»÷ʼþÀï¹Ø±ÕÒ³Ã棬ƴ½Ó´úÂë¾ÍÊÇÁË
²¹³ä£¬²»¿ÉÄÜ£¬ÎÒ×Ô¼ºÊÔ¹ý£¬ÔÙ²¹³äÒ»ÏÂ
1.¹Ø±ÕʱÌáʾ“ÊÇ·ñ¹Ø±Õ”
Response.Write("<script language:javascript>javascript:window.close();</script>");
2.Ö±½Ó¹Ø±Õ²»Ìáʾ
Response.Write("<script language:javascrip ......