网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.有趣的lucene.net索引.
.UNIX时间戳与.net日期类的转换 .
.asp.net应用程序级别跟踪.
.ASP.NET控件开发之"代码紧凑原则".
.用MasterPage 代替 PageBase.
.一个简单的ASP.NET Forms 身份认.
.Sys.ScriptLoader与JS加载进度条.
.ASP.NET服务器控件PleaseWaitBut.
.ASP.net在页面所有内容生成后、输.
.DataTable操作中的性能问题.
.如何解决Remoting无法传输存储过.
.ASP.NET编程中的十大技巧.
.翻译 一些很酷的.Net技巧.
.asp.net(C#)海量数据表高效率分页.
.从数据库导出数据到word、excel、.
.基于Gettext的asp.net网站多语言.
.ASP.NET生成高质量缩略图通用函数.
.在MasterPage中檢驗User是否登入.
.通过web.config设置数据库连接串.
.Asp.net2.0:如何使用ObjectData.

数据岛出到Excel最为简易的方法

发表日期:2006-6-20


只需将ContentType 设置为 "application/vnd.ms-excel",表示以Excel方式输出.
代码如下:
DataToExcel.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataToExcel.aspx.cs" Inherits="DataToExcel" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>DataToExcel</title>
</head>
<body>
    <form id="form1" runat="server">
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
    </form>
</body>
</html>DataToExcel.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class DataToExcel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Response.ContentType = "application/vnd.ms-excel";
            string ConnStr = "server=localhost;uid=sa;pwd=;database=northwind";
            SqlConnection Conn = new SqlConnection(ConnStr);
            Conn.Open();
            string sqlcmd = "select lastname,firstname,title, address, city from employees";
            SqlCommand cmd = new SqlCommand(sqlcmd, Conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            this.GridView1.DataSource = ds.Tables[0].DefaultView;
            this.GridView1.DataBind();
        }
    }
}
http://ring1981.cnblogs.com/archive/2006/06/19/429919.html

上一篇:一些常用的数据操作类 人气:5953
下一篇:请求网址并解析返回的html 人气:5831
浏览全部数据岛的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐