博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Repeater控件数据导出Excel
阅读量:7056 次
发布时间:2019-06-28

本文共 2452 字,大约阅读时间需要 8 分钟。

本演示中,我们实现这个Repeater控件数据导出Excel的功能。

我们准备一个对象:

View Code
Imports Microsoft.VisualBasicNamespace 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 ClassEnd Namespace

准备数据来填充上面创建好的对象:

View Code
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 = "护手霜"        cls.Add(cl)        Return cls    End Function

在.aspx页面拉一个Repeater控件:

View Code
ID Name
<%# Eval("ID")%> <%# Eval("Name")%>

然在.aspx.vb为Repeater控件绑定数据:

View Code
Imports Insus.NETPartial 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 SubEnd Class

ok,一切准备绪,我们在.aspx拉一个铵钮,让用户点击此铵钮时,能对Repeater控件的数据导出Excel。

铵钮拉好,我们要去.aspx.vb写onClick事件,在写之前,首先下载一个 解压之后放入BIN目录中。

View Code
Protected Sub Button1_Click(sender As Object, e As EventArgs)        Dim obj As New InsusExportToExcel()  '实例化对象。        obj.ExportToExcel(Me.RepeaterCatalog, "catalog") '传入Repeater控件以入导出的Excel文件名。    End Sub

当然最后,少不了演示:

 

转载地址:http://rtool.baihongyu.com/

你可能感兴趣的文章
CHAR、TCHAR、WCHAR_T之间的区别与问题
查看>>
sql小计合计
查看>>
安装Java
查看>>
Ubuntu Linux输入法fcitx方块乱码解决设置
查看>>
node递归批量重命名指定文件夹下的文件
查看>>
python if not用法
查看>>
python-2
查看>>
选择器
查看>>
springMVC参数的获取区别
查看>>
win7电脑数字键盘失灵怎么办
查看>>
java及java web学习笔记
查看>>
SpringMVC+Spring+hibernate整合及分页
查看>>
OpenAI教程
查看>>
LeetCode:459. Repeated Substring Pattern
查看>>
Database Resource website
查看>>
牛客寒假6-E.海啸
查看>>
linq 读取xml
查看>>
const 总结
查看>>
@RestController注解下返回到jsp视图页面
查看>>
搜索框请输入关键字 onfocus 和 onblur
查看>>