首页上一页 1 下一页尾页 2 条记录 1/1页
将数据库数据传递给WORD的问题
发表在ASP.NET图书答疑
2011-04-02
是否精华
是
否
版块置顶:
是
否
ASP.net完全自学手册,第168-169页的程序。在点击BOTTUM健后,文件下载窗口为什么一闪就没有了,什么原因呢?
我的程序代码如下:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.IO;
public partial class tcbb : System.Web.UI.Page
{
public void export(string FileType, string FileName)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlDecode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public SqlConnection GetConnection()
{
string mystr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myconn = new SqlConnection(mystr);
return myconn;
}
private void bind()
{
}
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myconn = GetConnection();
myconn.Open();
string sqlstr = "select * from tczl";
DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, myconn);
myda.Fill(myds, "tczl");
GridView1.DataSource = myds;
GridView1.DataBind();
myda.Dispose();
myds.Dispose();
myconn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
export("application/ms-word", "tt.doc");
}
public override void VerifyRenderingInServerForm(Control control)
{
}
}
我的程序代码如下:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.IO;
public partial class tcbb : System.Web.UI.Page
{
public void export(string FileType, string FileName)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlDecode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public SqlConnection GetConnection()
{
string mystr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myconn = new SqlConnection(mystr);
return myconn;
}
private void bind()
{
}
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myconn = GetConnection();
myconn.Open();
string sqlstr = "select * from tczl";
DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, myconn);
myda.Fill(myds, "tczl");
GridView1.DataSource = myds;
GridView1.DataBind();
myda.Dispose();
myds.Dispose();
myconn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
export("application/ms-word", "tt.doc");
}
public override void VerifyRenderingInServerForm(Control control)
{
}
}