读书人

增加textbox及保存其中内容的有关问题

发布时间: 2012-09-13 09:51:52 作者: rapoo

增加textbox及保存其中内容的问题


选择combobox中数字,点“增加”,会显示数字对数的textbox,在textbox中录入数据,
点“保存”,会把textbox中数据保存进数据库中。

例如图:选择4,点增加,就增加4对textbox和4个“删除”,在textbox中录入数据,点“保存”,把每一对中的前后textbox内容分别保存进对应数据库表中。

可不可以实现?
谢谢各位!




[解决办法]
方法很多,可以定义textbox数组,自己根据索引访问
或者每行(两个textbox和一个按钮)做成一个自定义组件
[解决办法]

C# code
        private void btnAdd_Click(object sender, EventArgs e)        {            if (!string.IsNullOrEmpty(comboBox1.Text))             {                int n = Convert.ToInt32(comboBox1.Text);                for (int i = 0; i < n; i++)                {                    TextBox txt1 = new TextBox();                    txt1.Width = 100;                    txt1.Height = 22;                    txt1.Location = new Point(50, i * 22 + 3 * (i + 1));                    TextBox txt2 = new TextBox();                    txt2.Width = 100;                    txt2.Height = 22;                    txt2.Location = new Point(160, i * 22 + 3 * (i + 1));                    Button btn = new Button();                    btn.Width = 75;                    btn.Height = 22;                    btn.Location = new Point(260, i * 22 + 3 * (i + 1));                    btn.Text = "删除";                    this.Controls.Add(txt1);                    this.Controls.Add(txt2);                    this.Controls.Add(btn);                }            }        } 

读书人网 >C#

热点推荐