Repeater control data export Excel (with demo animation)

Source: Internet
Author: User

In this demonstration, we implement the Repeater control data export Excel function.
We prepare an object:

Copy codeThe Code is as follows: 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

Prepare data to fill in the object created above:Copy codeThe Code is As follows: 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 = "lipstick" cls. add (cl) cl = New Catalog () cl. ID = 2 cl. name = "rouge" cls. add (cl) cl = New Catalog () cl. ID = 3 cl. name = "Lotion" cls. add (cl) cl = New Catalog () cl. ID = 4 cl. name = "hand cream" cls. add (cl) Return cls End Function

Pull a Repeater control on the. aspx page:Copy codeThe Code is as follows: <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>

However, in. aspx. vb, bind data to the Repeater control.:Copy codeThe Code is as follows: 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. All preparations. We pull an button in. aspx so that you can click this button to export the data of the Repeater control to Excel.Copy codeThe Code is as follows: <asp: Button ID = "Button1" runat = "server" Text = "Export to Excel" OnClick = "button#click"/>

Pull the button. We will go to. aspx. vb to write the onClick event. before writing, first download an InsusExportToExcel Library and decompress it into the BIN directory.Copy codeThe Code is As follows: Protected Sub button#click (sender As Object, e As EventArgs)
Dim obj As New InsusExportToExcel () 'instantiate an object.
Obj. ExportToExcel (Me. RepeaterCatalog, "catalog") 'imports the Repeater control to import the exported Excel file name.
End Sub

At the end of the lecture:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.