欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Repeater控件數(shù)據(jù)導(dǎo)出Excel(附演示動(dòng)畫)

 更新時(shí)間:2013年01月16日 09:16:05   作者:  
本文我們實(shí)現(xiàn)為Repeater控件數(shù)據(jù)導(dǎo)出Excel的功能,附動(dòng)畫演示,感興趣的朋友可以了解下

本演示中,我們實(shí)現(xiàn)這個(gè)Repeater控件數(shù)據(jù)導(dǎo)出Excel的功能。
我們準(zhǔn)備一個(gè)對(duì)象

復(fù)制代碼 代碼如下:

Imports Microsoft.VisualBasic
Namespace Insus.NET
Public Class Catalog
Private _ID As Integer
Private _Name As String
Public Property ID As Integer
Get
Return _ID
End Get
Set(value As Integer)
_ID = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
End Class
End Namespace

準(zhǔn)備數(shù)據(jù)來填充上面創(chuàng)建好的對(duì)象
復(fù)制代碼 代碼如下:

Private Function GetData() As List(Of Catalog) Dim cls As New List(Of Catalog) Dim cl As Catalog = New Catalog() cl.ID = 1 cl.Name = "唇膏" cls.Add(cl) cl = New Catalog() cl.ID = 2 cl.Name = "胭脂" cls.Add(cl) cl = New Catalog() cl.ID = 3 cl.Name = "化妝水" cls.Add(cl) cl = New Catalog() cl.ID = 4 cl.Name = "護(hù)手霜" cls.Add(cl) Return cls End Function

在.aspx頁面拉一個(gè)Repeater控件
復(fù)制代碼 代碼如下:

<asp:Repeater ID="RepeaterCatalog" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td>ID
</td>
<td>Name
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("ID")%>
</td>
<td>
<%# Eval("Name")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

然在.aspx.vb為Repeater控件綁定數(shù)據(jù)
復(fù)制代碼 代碼如下:

Imports Insus.NET
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Data_Binding()
End If
End Sub
Private Sub Data_Binding()
Me.RepeaterCatalog.DataSource = GetData()
Me.RepeaterCatalog.DataBind()
End Sub
End Class

ok,一切準(zhǔn)備緒,我們在.aspx拉一個(gè)銨鈕,讓用戶點(diǎn)擊此銨鈕時(shí),能對(duì)Repeater控件的數(shù)據(jù)導(dǎo)出Excel。
復(fù)制代碼 代碼如下:

<asp:Button ID="Button1" runat="server" Text="Export to Excel" OnClick="Button1_Click" />

銨鈕拉好,我們要去.aspx.vb寫onClick事件,在寫之前,首先下載一個(gè)InsusExportToExcel Library 解壓之后放入BIN目錄中。
復(fù)制代碼 代碼如下:

Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim obj As New InsusExportToExcel() '實(shí)例化對(duì)象。
obj.ExportToExcel(Me.RepeaterCatalog, "catalog") '傳入Repeater控件以入導(dǎo)出的Excel文件名。
End Sub

當(dāng)然最后,少不了演示

相關(guān)文章

最新評(píng)論