• NET Repeater控件使用


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx.cs" Inherits="OprateWordWebSite.Repeater" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div>
            <asp:Button ID="btnExport" runat="server" Text="导出数据"
                onclick="btnExport_Click" /></div>
        <asp:Repeater id="rptEmp" runat="server">
      <HeaderTemplate>
      <div  style="text-decoration: underline; font-family: 宋体, Arial, Helvetica, sans-serif; font-size: 18px; position: relative; text-align: center;">Repeater Header</div>
      
       <div style="text-align: right">2010年05月&nbsp;&nbsp;&nbsp;&nbsp</div>
        <table width="100%" border="1" cellspacing="0" cellpadding="0">   
        <tr align="center" bgcolor="#3399FF">
       <td>员工编号</td>
       <td>员工姓名</td>
       <td>所属职位</td>
       <td>上级编号</td>
       <td>工资水平</td>
       </tr>
      </HeaderTemplate>
      <ItemTemplate>
       <tr align="center">
       <td><%# DataBinder.Eval(Container.DataItem, "EMPNO") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "ENAME") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "JOB") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "MGR") %></td>
       <td><%# DataBinder.Eval(Container.DataItem, "SAL") %></td>
       </tr>
      </ItemTemplate>
      <FooterTemplate>
       </table>
      </FooterTemplate>
    </asp:Repeater>

        </div>
        </form>
    </body>
    </html>

    ---------------------后台----------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.OracleClient;
    using System.Text;
    using System.IO;

    namespace OprateWordWebSite
    {
        public partial class Repeater : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    using (OracleConnection conn = new OracleConnection("Data Source=orcl;user=scott;password=wang131421"))
                    {
                        OracleCommand cmd = new OracleCommand("select * from emp", conn);

                        OracleDataAdapter da = new OracleDataAdapter(cmd);

                        DataSet ds = new DataSet();

                        da.Fill(ds, "emp");

                        rptEmp.DataSource = ds.Tables[0];
                        rptEmp.DataBind();
                    }
                }
            }

            public override void VerifyRenderingInServerForm(Control control)
            {

            }


            /// <summary>
            ///
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void btnExport_Click(object sender, EventArgs e)
            {
                Response.ClearContent();

                Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");

                Response.ContentType = "application/excel";

                StringWriter sw = new StringWriter();

                HtmlTextWriter htw = new HtmlTextWriter(sw);

                rptEmp.RenderControl(htw);

                Response.Write(sw.ToString());

                Response.End();
     

            }
        }
    }

  • 相关阅读:
    1、线性DP 213. 打家劫舍 II
    如何在CentOS 8上安装Vtiger CRM?
    如何在不使用密码的情况下切换(su)到另一个用户帐户
    如何解决Ubuntu上的Busybox Initramfs错误
    Linux中的16个Echo命令示例
    如何在Ubuntu 20.04 LTS Focal Fossa上安装Grafana
    如何在Ubuntu 20.04上安装Apache ZooKeeper
    如何在Ubuntu 20.04 LTS Focal Fossa上安装Prometheus
    如何在CentOS 8上安装GlassFish
    如何在CentOS 8上安装Netdata Monitoring
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1709684.html
Copyright © 2020-2023  润新知