1、display.asp代码
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick="btnUpload_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="Has Header ?" />
<asp:RadioButtonList ID="rbHDR" runat="server">
<asp:ListItem Text = "Yes" Value = "Yes" Selected = "True" >
</asp:ListItem>
<asp:ListItem Text = "No" Value = "No"></asp:ListItem>
</asp:RadioButtonList>
<asp:GridView ID="GridView1" runat="server"
OnPageIndexChanging = "PageIndexChanging" AllowPaging = "true">
</asp:GridView>
2、绑定excel的配置文件webConfig.xml:
<connectionStrings>
<add name ="Excel03ConString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}
Extended Properties='Excel 8.0HDR={1}'"/>
<add name ="Excel07ConString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0Data Source={0}
Extended Properties='Excel 8.0HDR={1}'"/>
</connectionStrings>
3、后端c#代码:
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName)
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName)
string FolderPath = ConfigurationManager.AppSettings["FolderPath"]
string FilePath = Server.MapPath(FolderPath + FileName)
FileUpload1.SaveAs(FilePath)
Import_To_Grid(FilePath, Extension, rbHDR.SelectedItem.Text)
}
}
这样的:<asp:DataList>
<HeaderTemplate>
表格的第一行样式(表头)
</HeaderTemplate>
<ItemTemplate>
表格正文内容(如Table标签)
</ItemTemplate>
<FooterTemplate>
表格的最后一行样式
</FooterTemplate>
</asp:DataList>
DataList里面可以根据需要自己定义模板,非常好用。
姓名什么的都放在headtemplate里面,下面itemtemplate里面放一个table,里面几行几列的放什么控件你应该会做,然后边框线你只需要把table的边框线做出来就行了,datalist循环就显示出来了欢迎分享,转载请注明来源:内存溢出
评论列表(0条)