C# 将字符串转换为文本框名称
可能的重复:
C# 通过名称获取控制
我现在一直在寻找答案有一段时间了,想知道是否有人可以帮助我。
我想将 String 类型转换为 TextBox 类型,如下所示。
String text = "textBox" + number;
TextBox tb = text;
我想这样做,这样我就能收到号码,然后知道要写入哪个文本框。
任何帮助将不胜感激! :)
Possible Duplicate:
C# Get control by name
I have been looking around for an answer for this now for a while and was wondering if someone would help me please.
I would like to convert a type String into type TextBox so say below.
String text = "textBox" + number;
TextBox tb = text;
I would like to do this so I receive the number and then I know which textBox to write to.
Any help would be most appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,您可以使用反射来获取变量,但我认为您真正想要的是找到实际的控制。
使用 FindControl 方法获取对实际文本框的引用:
Well, you could get the variable using reflection, but what I think that you really want to is to just find the actual control.
Use the
FindControl
method to get a reference to the actual textbox:您有一系列文本框吗?
那是Windows窗体/Web吗?
基本上,您可以找到遍历容器的 Controls 集合并找到具有 ID 的元素。
请注意,我的答案相当广泛,并非在所有情况下都准确。如果您提供更多详细信息,我将进一步帮助您。
Do you have an array of text boxes?
Is that windows form / web?
Basically what you can to is find to go through the Controls collection of the container and find an element with the the ID.
Note that my answer is pretty wide and not accurate on all cases. If you'll provide more details I'll help you further.