首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

嵌套中的FindControl解决思路

2012-02-02 
嵌套中的FindControlVB codePrivate Sub ppbind()Dim it As RepeaterItemDim db As Integer 0For Each i

嵌套中的FindControl

VB code
Private Sub ppbind()   Dim it As RepeaterItem   Dim db As Integer = 0   For Each it In Repeater1.Items       Dim al As Label = it.FindControl("all")       db = db + Convert.ToDouble(al.Text)   Next   ll1.Text = "$" + db.ToString()End Sub

此段代码现在我要在Repeater1中的Repeater2中实现此功能
代码这样写有问题么
VB code
Private Sub ppbind()   Dim it As RepeaterItem   Dim db As Integer = 0   For Each it In Repeater1.Items       Dim rep As Repeater= it.FindControl("Repeater2")       dim it2 as RepeaterItem      For Each it2 In rep.Items      Dim al As Label = it2.FindControl("all")      db = db + Convert.ToDouble(al.Text)      Next   Next   ll1.Text = "$" + db.ToString()End Sub


[解决办法]
那你自己试有没有问题呢?

这样的findcontrol,最好在repeater的item绑定事件中去写,就不需要foreach循环找了

热点排行