c#在代码中更改文本框名称 [英] c# change textbox name in code

查看:24
本文介绍了c#在代码中更改文本框名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道这样的事情是否可能:

i was just wondering if something like this is possible:

for(int i = 0; i < 7; i++)
{
    textbox + i + .text = aString;
}

我想更改一段代码以处理多个文本框,而不必键入整个代码 6 次.有谁知道这是否可能以及如何实现?谢谢:3

I want to change a piece of code to work on multiple textboxes, without having to type the whole code 6 times. does anyone know if this is possible and how? Thanks :3

推荐答案

在 C# 中,您可以在页面 aspx 中找到您的控件.

in C# you can find your control in your page aspx.

示例:

for (int i = 0; i < 10; i++)
 {

     TextBox textBox = this.Page.FindControl("textbox" + i.ToString()) as TextBox;
     if (textBox != null)
     {
        textBox.Text = "change Text";
     }
  }

这篇关于c#在代码中更改文本框名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆