日期:2014-05-18  浏览次数:20389 次

嵌套中的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循环找了