将Excel中数据读入到GridView中
2009-04-28 18:25
288 查看
1、页面代码:
.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
2、执行代码
.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:PanelID="Panel1"runat="server"BorderWidth="3px">
<asp:GridViewID="GridView1"runat="server"
AllowPaging="True"onpageindexchanging="GridView1_PageIndexChanging"
Width="702px">
</asp:GridView>
</asp:Panel>
<p>
<asp:ButtonID="Button1"runat="server"Text="读取数据"onclick="Button1_Click"
style="height:26px"/>
</p>
</form>
</body>
</html>
.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
2、执行代码
usingSystem;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Data.OleDb;
publicpartialclassDefault2:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
GridView1.DataSource=CreateDataSource();
GridView1.DataBind();
}
privateDataSetCreateDataSource()
{
stringconnString;
connString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath("Checklist.xls")+";ExtendedProperties=Excel8.0;";
OleDbConnectionolecon=newOleDbConnection(connString);
OleDbDataAdaptermyda=newOleDbDataAdapter("SELECT*FROM[Sheet1$]",connString);
DataSetmyds=newDataSet();
myda.Fill(myds);
returnmyds;
}
protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse)
{
GridView1.PageIndex=e.NewPageIndex;
GridView1.DataSource=CreateDataSource();
GridView1.DataBind();
}
}
.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
相关文章推荐
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView?
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView --
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- 18.GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- GridView数据导入Excel/Excel数据读入GridView
- 数据导入Excel/Excel数据读入GridView
- 把Excel文件中的数据读入到DataGrid中
- asp.net 将GridView中的数据导出到Excel
- 将GridView控件数据导出到Excel中。
- GridView数据导出到Excel
- 动态创建gridview,导出Excel数据
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- asp.net 2.0 GridView导出数据到Excel