Repeater Control Data export Excel (with demo animation) _ Practical Tips

Source: Internet
Author: User
Tags eval prepare

In this demo, we implement the functionality of this Repeater control data export Excel.
we prepare an object :

Copy Code code 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 populate the objects created above
Copy Code code 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 All 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 = "Cosmetic Water" 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 Code code 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>

But in. Aspx.vb bind data for the Repeater control
Copy Code code 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 ready threads, we are in. aspx pull an ammonium button, so that when the user clicks on the Ammonium button, the Repeater control data can be exported Excel.
Copy Code code as follows:

<asp:button id= "Button1" runat= "Server" text= "Export to Excel" onclick= "Button1_Click"/>

The Ammonium button pulls well, we're going to. aspx.vb write the OnClick event, before writing, first download a insusexporttoexcel Library after decompression into the bin directory.
Copy Code code as follows:

Protected Sub button1_click (sender as Object, E as EventArgs)
Dim obj as New insusexporttoexcel () instantiates the object.
Obj. exportToExcel (Me.repeatercatalog, "catalog") ' passes in the Repeater control to the exported Excel file name.
End Sub

of course, finally, the demo

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.