博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取Repeter的Item和ItemIndex
阅读量:6550 次
发布时间:2019-06-24

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

首先看看效果:

 

 Repeater控件,放在ItemTemplate内的铵钮OnClick之后,获取Repeater的Item,ItemIndex,CommandArgument,CommandName以及绑定的字段值。

准备数据:

View Code
1 Imports Microsoft.VisualBasic 2 Namespace Insus.NET 3  4     Public Class Catalog 5  6         Private _ID As Integer 7         Private _Name As String 8  9         Public Property ID As Integer10             Get11                 Return _ID12             End Get13             Set(value As Integer)14                 _ID = value15             End Set16         End Property17 18         Public Property Name As String19             Get20                 Return _Name21             End Get22             Set(value As String)23                 _Name = value24             End Set25         End Property26 27     End Class28 End Namespace

 

View Code
1  Private Function GetData() As List(Of Catalog) 2         Dim cls As New List(Of Catalog) 3  4         Dim cl As Catalog = New Catalog() 5         cl.ID = 1 6         cl.Name = "汽车" 7         cls.Add(cl) 8  9         cl = New Catalog()10         cl.ID = 211         cl.Name = "时尚"12         cls.Add(cl)13 14         cl = New Catalog()15         cl.ID = 316         cl.Name = "科技"17         cls.Add(cl)18 19         cl = New Catalog()20         cl.ID = 521         cl.Name = "文化"22         cls.Add(cl)23 24         cl = New Catalog()25         cl.ID = 626         cl.Name = "公益"27         cls.Add(cl)28         Return cls29     End Function

在.aspx放置Repeater控件:

View Code
ID Name Choose

在.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

接下来,我们写onclick事件,在写事件之前,先在.aspx放一个Label来显示事件结果:

View Code
Process infor:

 

View Code
Protected Sub Button1_Click(sender As Object, e As EventArgs)        Dim btn As Button = DirectCast(sender, Button)        Dim commandArgument As String = btn.CommandArgument        Dim commandName As String = btn.CommandName        Dim item As RepeaterItem = DirectCast(btn.NamingContainer, RepeaterItem)        Dim index As Integer = item.ItemIndex        Dim id As String = DirectCast(item.FindControl("LabelID"), Label).Text        Dim name As String = DirectCast(item.FindControl("LabelName"), Label).Text        Me.LabelInfo.Text = String.Format("Item index: {0}; CommandArgument: {1}; CommandName: {2}; ID: {3}; Name: {4};", index, commandArgument, commandName, id, name)    End Sub

 

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

你可能感兴趣的文章
开始学习java
查看>>
Android数据存储之SQLite的操作
查看>>
工作日志2014-08-19
查看>>
各个平台 如何安装 Ruby 和 RubyGems
查看>>
九. 200创业教训万元获得--“神刻”这是忽悠?
查看>>
eclipse maven plugin 插件 安装 和 配置
查看>>
Swift - 控制流/控制结构说明(if,switch,for,while)
查看>>
五个有用的jquery小技巧
查看>>
算法-三向字符串快速排序
查看>>
Spring 3.1新特性之二:@Enable*注解的源码,spring源码分析之定时任务Scheduled注解
查看>>
Oracle DISTINCT A 排序问题(转)
查看>>
Objective-C:KVC机制
查看>>
身份证查询API
查看>>
iText5报表_页眉与页脚
查看>>
javascript:void(0) ,设置a链接无效,设置点击a页面不刷新,不跳动
查看>>
两台linux服务器之间实现挂载
查看>>
keyup与setInterval
查看>>
python --批量重命名文件名
查看>>
QQ三方登录
查看>>
NTP方式保证以时间戳同步可靠性
查看>>