添加多个文本框并检索其值。 [英] Add multiple text boxes and retrieve there value.

查看:77
本文介绍了添加多个文本框并检索其值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个窗口应用程序。我希望当我点击添加按钮时,它会动态创建一个一个文本框。我将数据存储在sql server数据库中并在数据网格视图中显示它们。那么你可以帮我添加和查看文本框值。

解决方案

要动态创建一些文本框,你可以在下面的代码中添加button_click的范围:

  private   void  button1_Click( object  sender,EventArgs e)
{
TextBox tb1 = new TextBox();
tb1.ID = textBox1;
tb1.Text = ;
yourform.Controls.Add(tb1)
}



此外,请尝试阅读以下帖子:

C#按钮单击

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/71526c3e-66a5-4309-bdc9-9e29064faef6 [ ^ ]


尝试:

  int  x =  20 ;  int  y =  20 ;  int  margin =  5 ; 
for int i = 0 ; i < 10 ; i ++)
{
TextBox tb = new TextBox();
tb.Location = new Point(x,y);
y + = tb.Height + margin;
Controls.Add(tb);
}

将创建十个文本框并将其显示在垂直堆栈中。访问它们:

  foreach (控制c  in 控制)
{
TextBox tb = c as TextBox;
if (tb!= null
{
.. 。
}
}

你究竟如何将它们保存到数据库取决于你 - 我不知道你的数据库结构,或者你正在尝试使用数据。


I working on a window application. I want that when I click on add button then it creates one by one text boxes dynamically. I store the data in the sql server database & show them in a data grid view. So can u help me for add and view the text box values.

解决方案

To create some text boxes dynamically you can add in scope of button_click following code:

private void button1_Click(object sender, EventArgs e)
{
   TextBox tb1 = new TextBox();
   tb1.ID = "textBox1";
   tb1.Text = "Hi";
   yourform.Controls.Add(tb1)
}


Also, try read the following post:
"C# Insert into SQL when button click"
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/71526c3e-66a5-4309-bdc9-9e29064faef6[^]


Try:

int x = 20; int y = 20; int margin = 5;
for (int i = 0; i < 10; i++)
   {
   TextBox tb = new TextBox();
   tb.Location = new Point(x, y);
   y += tb.Height + margin;
   Controls.Add(tb);
   }

Will create ten text boxes and display them in a vertical stack. To access them:

foreach( Control c in Controls)
   {
   TextBox tb = c as TextBox;
   if (tb != null)
      {
      ...
      }
   }

Exactly how you save them to your database is up to you - I have no idea of your DB structure, or what you are trying to with the data.


这篇关于添加多个文本框并检索其值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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