All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
IsPostBack深入分析_[Asp.Net教程]
浏览UTF-8编码的网页出现空白解决方法_php资料_编程技术
C#教程:线程的创建
经典:学习动态网页PHP技术常见问题汇总解答_php资料_编程技术
ASP.NET实例:增强,GridView,控件的功能(二)_[Asp.Net教程]
点击gridview的删除按钮弹出确认消息框_[Asp.Net教程]
网页制作技巧:设计干净的链接_[Html教程]
让Apache支持ASP.NET_[Asp.Net教程]
防止用户上传产生无效文件源码_[Asp.Net教程]
Sql,Server2005实现远程备份数据库_mssql学习_编程技术
Reading number is top 10 pictures
再发两张抽象画
Sora aoi in China4
这才是真正的人体艺术2
The little girl with long hair1
西游日记3
Ashlynn Brooke photograph of a group2
好身材能把衣服穿出3D效果
自己约的炮,含泪也要打完
So beauty, will let you spray blood10
The real super beauty2
Download software ranking
Such love down(擒爱记)
Tram sex maniac 2 (H) rar bag5
中国结婚习俗实录
星际争霸1.08硬盘免安装版
C#编程思想
Unix video tutorial19
Tram sex maniac 2 (H) rar bag19
Boxer's Top ten classic battle8
Sora aoi, the maid, students' uniforms
C#COM编程指南
delv published in(发表于) 2014/1/6 9:04:12 Edit(编辑)
ASP.NET技巧:数据导出到Excel最为简易的方法_[Asp.Net教程]

ASP.NET技巧:数据导出到Excel最为简易的方法_[Asp.Net教程]

ASP.NET技巧:数据导出到Excel最为简易的方法_[Asp.Net教程]

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




DataToExcel







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


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.