本文介绍了创建一个循环,将编辑文本框60名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本框SET1 = 1到30 =在查询
名称= br1id到br30id



文本框组2 = 1到30 =在结果输出



我不明白如何根据30不同势文本框的名称创建一个循环?



我不能复制粘贴这些线30次编辑文本框的名字,那尔德只看错了。

 
{

的MySqlConnection mysqlCon =新的MySqlConnection(
服务器= 195.159.253.229;+
数据库=布鲁克;+
用户ID =鲍比;+
密码= LoLOW ###;);

的MySqlCommand CMD1 =新的MySqlCommand(
选择brukernavn来自于Bruker其中ID ='+ br1id.Text +;,mysqlCon);

mysqlCon.Open();

navX [0] = cmd1.ExecuteScalar()的ToString();
br1txt3.Text = navX [0];
}


解决方案

您想使用。控制枚举



假设这是的WinForms:

 的foreach(在this.Controls控制三){
如果(c是文本框)
Console.WriteLine(c.Text);
}



而实际上,我认为,这将用于ASP.Net工作了。 (即使控制处于diferent命名空间。)



但!:这是一个DataGrid是为取得。


text box set1 = 1 to 30 = in the query name = br1id to br30id

textbox set 2 = 1 to 30 = in the result output

i dont understand how to create a loop based on 30 diffrent textbox names?

i cant copy paste these lines 30 times editing the textbox names, that wold just look wrong.

try
{

   MySqlConnection mysqlCon = new MySqlConnection(
      "server= 195.159.253.229;" +
      "Database = bruker;" +
      "user id=bobby;" +
      "password=LoLOW###;");  

   MySqlCommand cmd1 = new MySqlCommand(
      "SELECT brukernavn From bruker where ID = '" + br1id.Text + "';", mysqlCon);

   mysqlCon.Open();

   navX[0] = cmd1.ExecuteScalar().ToString();
   br1txt3.Text = navX[0];   
}
解决方案

You will want to use a control enumerator.

Assuming that this is WinForms:

foreach(Control c in this.Controls) {
    if(c is TextBox)
        Console.WriteLine(c.Text);   
}

And actually, I think that will work for ASP.Net, too. (Even though Control is in a diferent namespace.)

HOWEVER!: This is what a datagrid was made for.

这篇关于创建一个循环,将编辑文本框60名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:53