[英]Visual Basic looping controls
I have a web application that I'm writing. 我有一个我正在写的Web应用程序。 I have a lot of buttons, all named the same thing except with a number appended (button1,button2,button3...etc.).
我有很多按钮,除了附加一个数字(button1,button2,button3等等)之外,所有按钮都是相同的。 All of these are in a panel named Panel3.
所有这些都在名为Panel3的面板中。 I would like to loop through these blank ImageButtons and set their image using .ImageUrl.
我想循环使用这些空白的ImageButtons并使用.ImageUrl设置它们的图像。 I know my getIconImage() function works.
我知道我的getIconImage()函数有效。
Dim cntrl As Control
For Each cntrl In Me.Panel3.Controls
cntrl.ImageUrl = getIconImage(4)
Next
The problem is "cntrl" does not recognize .ImageUrl as an option. 问题是 “cntrl”无法识别.ImageUrl作为选项。 It is like it doesn't recognize itself as an ImageButton.
它就像它不认为自己是一个ImageButton。 I am using asp.net and vb.net.
我使用的是asp.net和vb.net。 Thanks!
谢谢!
(as a note: I have also tried "Me.Controls" with no such luck. Also, I have tried setting a temporary ImageButton object equal to "cntrl" and modifying the .ImageUrl from there.) (作为注释:我也尝试过“Me.Controls”而没有这样的运气。另外,我尝试设置一个等于“cntrl”的临时ImageButton对象并从那里修改.ImageUrl。)
You don't say what the issue is so i'll assume you need to check which type of control you are getting in the loop: 你没有说出问题是什么,所以我假设你需要检查你在循环中得到的控件类型:
Dim cntrl As Control
For Each cntrl In Me.Panel3.Controls
if TypeOf cntrl Is ImageButton Then
cntrl.ImageUrl = getIconImage(4)
End if
Next
Try this: 尝试这个:
For Each cntrl As ImageButton In Me.Panel3.Controls.OfType(Of ImageButton)
May have to do Imports System.Linq
可能要做
Imports System.Linq
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.