Kei*_* L. 2 vb.net asp.net types repeater findcontrol
我需要在我的 asp.net 应用程序的中继器中找到一个控件。
目前我正在使用,FindControl("IdOfControl")并且运行良好。
但是我需要按类型 ( ImageButton)找到一个控件。
我目前的代码:
For Each rptItem As RepeaterItem In myRepeater.Items
Dim imgBtn As ImageButton = TryCast(rptItem.FindControl("myImageBtn"), ImageButton)
AddHandler imgBtn.Click, AddressOf imgBtn_Click
Next
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似的东西:
For Each rptItem As RepeaterItem In myRepeater.Items
Dim imgBtn As ImageButton = TryCast(rptItem.FindControl(TypeOf ImageButton), ImageButton)
AddHandler imgBtn.Click, AddressOf imgBtn_Click
Next
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
尝试这个
您的要求
For Each ri As RepeaterItem In myRepeater.Items
For Each cn As Control In ri.Controls
If cn.[GetType]() = GetType(ImageButton) Then
Response.Write("ss")
Response.Write(vbLf)
End If
Next
Next
e.g
For Each cn As Control In form1.Controls
If cn.[GetType]() = GetType(ImageButton) Then
Response.Write("ss")
End If
Next
Run Code Online (Sandbox Code Playgroud)