• 输出表文件


     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
            HeaderStyle-HorizontalAlign="left" >
                             <Columns>
                             <asp:TemplateField HeaderText="标题" ItemStyle-HorizontalAlign="left">
                                     <ItemTemplate >
                                         <%# Eval("name")%>
                                     </ItemTemplate>
    
    <ItemStyle HorizontalAlign="Left" Width="300px"></ItemStyle>
                                 </asp:TemplateField>
                                 <asp:TemplateField HeaderText="网址" ItemStyle-HorizontalAlign="left">
                                     <ItemTemplate>
                                        /<%#Eval("")%>/p_<%#Eval("pId")%>
                                     </ItemTemplate>
    
    <ItemStyle HorizontalAlign="Left" Width="400px"></ItemStyle>
                                 </asp:TemplateField>
                             </Columns>
                             <HeaderStyle  HorizontalAlign="left"/>
                   </asp:GridView>
    
    
    protected void btndc_click(object sender, EventArgs e)
        {
            int num = 1000;
            if (txtdc.Text != "")
            {
                num = Convert.ToInt32(txtdc.Text);
            }
            GridView1.AllowPaging = false;
            GridView1.DataSource = DB.GetDataTable(参数);
            GridView1.DataBind();
    
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".xls");
            Response.ContentType = "application/vnd.ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.Charset = "";
            this.EnableViewState = false;
            StringWriter oStringWriter = new StringWriter();
            HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
    
            //输出到excel
            GridView1.RenderControl(oHtmlTextWriter);
            Response.Write(oStringWriter.ToString());
            Response.End();
    
        }
    
        public override void VerifyRenderingInServerForm(Control control)
        {
            if (!control.GetType().Equals(GridView1.GetType()))
            {
                base.VerifyRenderingInServerForm(control);
            }
        }
    

      

  • 相关阅读:
    《页面优化》-- 一个大话题,也是一个面试比较老俗的问题
    Single-SPA 前端微服务化 动态路由多系统合并
    浏览器的DNS缓存查看和清除
    es6 的类 class
    数据驱动表格| 根据json数据,自动生成合并式table
    隐式调用 以及使用技巧
    柯里化currying + 隐式调用 = 一个有名的add面试题
    工作笔记
    php升级版本
    git使用
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4713608.html
Copyright © 2020-2023  润新知