Tutorials to .com

Tutorials to .com » Dotnet » Foundation » Excel data island out to the most simple method of

Excel data island out to the most simple method of

Print View , by: iSee ,Total views: 13 ,Word Count: 317 ,Date: Tue, 25 Aug 2009 Time: 4:00 PM

Just ContentType set to "application/vnd.ms- Excel", said the way the output to Excel.
Code is as follows:
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


.NET foundation Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.