读书人

嵌套中的FindControl解决思路

发布时间: 2012-02-02 23:57:14 作者: rapoo

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

读书人网 >asp.net

热点推荐