zoukankan      html  css  js  c++  java
  • 输出表文件

     <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);
            }
        }
    

      

  • 相关阅读:
    Getting Started with ASP.NET Web API 2 (C#)
    借助StackView简化页面布局
    获取网络数据
    歌曲列表和频道列表
    自定义UIImage组件实现圆形封面,转动,以及模糊背景
    什么是CoreData?
    Swift
    PNChart图表绘制库的使用
    PathCover个人主页控件使用
    ProgressHUD进程提示控件的使用
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4713608.html
Copyright © 2011-2022 走看看