通过控件的引用迭代 [英] Iterate through a reference of controls
本文介绍了通过控件的引用迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有3个带有txtBox1,txtBox2,txtBox3的ID的文本框,如何为文本值引用它们?
Dim varStart as integer = 1
Dim varEnd as integer = 3
Dim myUID As TextBox
for i = varStart to varEnd
myUID。 ID =(" txtUID"& i.ToString)
如果(修剪(CType(myUID,TextBox).Text)<>"")那么
做点什么
结束如果
next
If I have 3 text boxes with ids of txtBox1, txtBox2, txtBox3, how does one reference them for the text values?
Dim varStart as integer=1
Dim varEnd as integer=3
Dim myUID As TextBox
for i = varStart to varEnd
myUID.ID = ("txtUID" & i.ToString)
If (Trim(CType(myUID, TextBox).Text) <> "") then
do something
End if
next
推荐答案
我对你的问题感到有些困惑。一般来说,你只需要引用它们txtBox1.Text,txtBox2.Text等等......
你能详细说明一下吗?
I''m a bit confused by your question. Generally you would just reference them txtBox1.Text, txtBox2.Text and so on...
Can you elaborate a bit more?
你如果您在网页上,则需要使用.FindControl(字符串ID)。
如果您使用的是Windows窗体,则需要创建.FindControl的功能
You would need to use .FindControl(string id) if you are on a webpage.
If you are in a windows form, you will need to create the functionality of .FindControl
Plater,
感谢您的回复。关于确切的语法仍然有点困惑。
将myUID作为字符串调整
myUID =" txtUID" &安培; i.ToString
Page.FindControl(CType(myUID,TextBox))
以上告诉我字符串无法转换为文本框
>
Dim myUID As TextBox
myUID.ID =" txtUID" &安培; i.ToString
在我使用.findControl引用Object引用未设置为对象的实例之前阻止了我。
你能告诉我你的意思吗?非常感谢。
Plater,
Thanks for the reply. Still a bit confused about the exact syntax.
Dim myUID As String
myUID = "txtUID" & i.ToString
Page.FindControl(CType(myUID, TextBox))
above tells me string cannot be converted to textbox
Dim myUID As TextBox
myUID.ID = "txtUID" & i.ToString
above stops me before I can reference using .findControl that the Object reference not set to an instance of an object.
Can you tell me what you mean? Thanks so much.
这篇关于通过控件的引用迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文