asp.net vb 用循环获取Repeater控件模版列里每一行的控件
3个回答
展开全部
.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %> ' ></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' ></asp:Label>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
.aspx.vb
Imports System.Collections.Generic
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim list As List(Of User)
list = New List(Of User)
Dim u1 As New User(1, "aa")
Dim u2 As New User(2, "bb")
list.Add(u1)
list.Add(u2)
Repeater1.DataSource = list
Repeater1.DataBind()
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
For Each item As RepeaterItem In Repeater1.Items
If CType(item.FindControl("Label1"), Label).Text = "2" Then
Response.Write(CType(item.FindControl("Label2"), Label).Text)
End If
Next
End Sub
End Class
Public Class User
Sub New()
End Sub
Sub New(ByVal id As String, ByVal name As String)
Me._id = id
Me._name = name
End Sub
Private _id As Integer = 0
Public Property Id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %> ' ></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' ></asp:Label>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
.aspx.vb
Imports System.Collections.Generic
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim list As List(Of User)
list = New List(Of User)
Dim u1 As New User(1, "aa")
Dim u2 As New User(2, "bb")
list.Add(u1)
list.Add(u2)
Repeater1.DataSource = list
Repeater1.DataBind()
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
For Each item As RepeaterItem In Repeater1.Items
If CType(item.FindControl("Label1"), Label).Text = "2" Then
Response.Write(CType(item.FindControl("Label2"), Label).Text)
End If
Next
End Sub
End Class
Public Class User
Sub New()
End Sub
Sub New(ByVal id As String, ByVal name As String)
Me._id = id
Me._name = name
End Sub
Private _id As Integer = 0
Public Property Id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim i As Integer
For i = 0 To Repeater.Items.Count
Dim abc As Label = Repeater.Items[i].FindControl("l1")
手里没vb,看了看好像没错
For i = 0 To Repeater.Items.Count
Dim abc As Label = Repeater.Items[i].FindControl("l1")
手里没vb,看了看好像没错
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你能看懂c#的吧
for (int i = 0; i < Repeater1.Items.Count; i++)
{
label lbs = (Label)Repeater1.Items[i].FindControl("l1");//获取每行的label控件
//你的后续操作
// 使用lbs来获取这一的来l1控件的属性
}
for (int i = 0; i < Repeater1.Items.Count; i++)
{
label lbs = (Label)Repeater1.Items[i].FindControl("l1");//获取每行的label控件
//你的后续操作
// 使用lbs来获取这一的来l1控件的属性
}
追问
我用FindControl查找不出来~~
追答
看你的报什么错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询