就如delphi中的FindComponent
for i := 1 to 9 do
begin
with TEdit(FindComponent('kh'+IntToStr(i))) do
begin
Left := 10;
Top := i * 20;
text:='';
end;
end;
这样可以利用循环读取或给它们赋值。
...全文
735打赏收藏
如何在web form中动态寻找对象
就如delphi中的FindComponent for i := 1 to 9 do begin with TEdit(FindComponent('kh'+IntToStr(i))) do begin Left := 10; Top := i * 20; text:=''; end; end; 这样可以利用循环读取或给它们赋值。
Dim Obj As Object
For Each Obj In Me.Controls(1).Controls
Select Case Obj.GetType.ToString
Case "System.Web.UI.WebControls.TextBox"
Select Case Obj.ID
Case "textbox1"
Dim FormControl As Control
FormControl = Me.FindControl("Form1");'一般是Form1,根据你的Form名称改吧。
Dim ChildElement As Control
For Each ChildElement In FormControl.Children
If ChildElement.GetType.ToString = "System.Web.UI.WebControls.TextBox" Then '这里是你需要的类型字符串,如System.Web.UI.WebControls.TextBox
With CType(ChildElement,TextBox)
.Style("left") = "10"
.Style("Top") = "20"
.Text = ""
End With
End IF
Next