日期:2014-05-17  浏览次数:20460 次

类型“Button”的控件“replist_Button2_0”必须放在具有 runat=server 的窗体标记内。Repeater导出数据出错
protected void BtnPrint_Click(object sender, EventArgs e)
        {
            //定义文档类型、字符编码
            string title = "**统计表" + "_" + DateTime.Today.ToShortDateString();
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";

            string filename = "attachment;filename=" + System.Web.HttpUtility.UrlEncode(title, System.Text.Encoding.UTF8) + ".xls";
            Response.AppendHeader("Content-Disposition", filename);
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            //Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
            Response.ContentType = "application/ms-excel";
            Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");

            this.EnableViewState =true;
            // 定义一个输入流
            System.IO.StringWriter os = new System.IO.StringWriter();
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            this.replist.RenderControl(oHtmlTextWriter);
            //this 表示输出本页,你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
            Response.Write(oStringWriter.ToString());
            Response.End();

        }


前台:
 <table id="table1" >
            <tr>
             <th>
                  &nbsp 活动名
                </th>
                 <th >
                  &nbsp  活动封面