详细代码如下:
Default.aspx
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5
<html xmlns="http://www.w3.org/1999/xhtml" >
6
<head runat="server">
7
<title>Untitled Page</title>
8
</head>
9
<body>
10
<form id="form1" runat="server">
11
<div>
12
<asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 0px; position: absolute;
13
top: 0px">
14
</asp:GridView>
15
16
</div>
17
</form>
18
</body>
19
</html>
20
Default.aspx.cs
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10
using System.Data.OleDb;
11
12
public partial class _Default : System.Web.UI.Page
13

{
14
protected void Page_Load(object sender, EventArgs e)
15
{
16
if (!IsPostBack)
17
{
18
string connectionString = "provider=microsoft.jet.oledb.4.0;data source=D:/WebSites/ReadExcel/App_Data/message.xls;extended properties=excel 8.0";
19
OleDbConnection myConnection = new OleDbConnection(connectionString);
20
OleDbCommand myCommand = new OleDbCommand("select * from [Sheet1$]", myConnection);
21
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand);
22
DataSet ds = new DataSet();
23
myAdapter.Fill(ds);
24
GridView1.DataSource = ds;
25
GridView1.DataBind();
26
}
27
}
28
}
29

2

3

4

5

6

7

8

9

10

11

12

13



14

15



16

17



18

19

20

21

22

23

24

25

26

27

28

29
