protected void Button1_Click1(object sender, EventArgs e) { int gid = Convert.ToInt32(Convert.ToInt32(Request["Gid"])); StringBuilder sb = new StringBuilder(); sb.Append("select '编号=cu.UnitName,'姓名'=cu.JPName,'价格'=ct.Price,'时间'=ct.TenderTime"); sb.Append(" from cms_tenders ct,CMS_UserDetail cu where cu.ID=ct.UserID and ct.generalid="+gid); Response.Clear(); Response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.AddHeader("content-disposition", "attachment;filename=编号"+gid+"信息.xls"); Response.Charset = "gb2312"; Response.ContentType = "application/vnd.xls"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); //htmlWrite.Encoding = System.Text.Encoding.GetEncoding("gb2312"); //GridView1.AllowPaging = false; //BindData(); //GridView1.RenderControl(htmlWrite); if (DBHelper.ConnectionString == "") DBHelper.ConnectionString = ConfigurationManager.AppSettings["DefaultConnectionString"].ToString(); GridView gv = new GridView(); //string strSql = "select * from CMS_Content c ,CMS_U_News n where c.GeneralID=n.GeneralID and ModelID=1 "; //string strSearch = ""; //if (PublishDate.Value.Trim() != "") //{ // strSearch += " and DateCreated>=convert(datetime,'" + PublishDate.Value + "')"; //} //if (txtEndDate.Value.Trim() != "") //{ // strSearch += " and DateCreated<convert(datetime,'" + txtEndDate.Value + " 23:59:59')"; //} //strSql += strSearch; gv.DataSource = DBHelper.ExecuteDataSet(sb.ToString()); gv.DataBind(); gv.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }