我想在单击按钮时将一些面板动态添加到单个面板中。每个动态面板由水平方向的多个文本框组成。然后我想将这些文本框值保存到数据库中。
我已完成将动态面板和水平多个文本框添加到该面板中。但不知道如何将它们保存到数据库中。
这是我写的代码:
    int v = 0;
    TextBox txt1;
    TextBox txt2;
    TextBox txt3;
    TextBox txt4;
    TextBox txt5;
    ComboBox cmb4;
    public void tett()
    {
        v = 0;
        Panel whitePanel = new Panel();
        whitePanel.Name = "wt";
        // Quantity
        txt1 = new TextBox();
        txt1.Location = new Point(192, 38);
        txt1.Size = new Size(120, 24);
        txt1.Name = "text" + v ;
        txt1.Text = txt1.Name;
        v = v + 1;
        // Total Price
        txt2 = new TextBox();
        txt2.Location = new Point(566, 38);
        txt2.Size = new Size(120, 24);
        txt2.Name = "text" + v;
        txt2.Text = txt2.Name;
        txt2.TextChanged += Txt2_TextChanged;
        v = v + 1;
        // Unit Price
        txt3 = new TextBox();
        txt3.Location = new Point(753, 38);
        txt3.Size = new Size(120, 24);
        txt3.Name = "text" + v;
        txt3.Text = txt3.Name;
        v = v + 1;
        // Sell Price
        txt4 = new TextBox();
        txt4.Location = new Point(903, 38);
        txt4.Size = new Size(120, 24);
        txt4.Name = "text" + v;
        txt4.Text = txt4.Name;
        v = v + 1;
        // Product
        txt5 = new TextBox();
        txt5.Location = new Point(5, 38);
        txt5.Size = new Size(120, 24);
        txt5.Name = "text" + v;
        txt5.Text = txt5.Name;
        txt5.AutoCompleteSource = AutoCompleteSource.CustomSource;
        txt5.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        txt5.MouseClick += textBox5_MouseClick;
        Label lbl3 = new Label();
        Label lbl4 = new Label();
        Label lbl5 = new Label();
        Label lbl6 = new Label();
        Label lbl7 = new Label();
        Label lbl8 = new Label();
        lbl3.Location = new Point(5, 15);
        lbl3.Text = "Product";
        lbl4.Location = new Point(192, 15);
        lbl4.Text = "Quantity";
        lbl5.Location = new Point(379, 15);
        lbl5.Text = "Unit";
        lbl6.Location = new Point(566, 15);
        lbl6.Text = "Total Price";
        lbl7.Location = new Point(753, 15);
        lbl7.Text = "Unit Purchase Price";
        lbl8.Location = new Point(903, 15);
        lbl8.Text = "Unit Sell Price";
        cmb4 = new ComboBox();
        // Unit
        cmb4.Location = new Point(379, 38);
        cmb4.Size = new Size(120, 24);
        whitePanel.BackColor = ColorTranslator.FromHtml("#ECF0F5");
        whitePanel.Location = new Point(1, a * 10);
        whitePanel.Size = new Size(1330, 60);
        var _button = new Button();
        _button.Text = "Dispose";
        _button.Name = "DisposeButton";
        _button.Location = new Point(1053, 38);
        _button.MouseClick += _button_MouseClick;
        whitePanel.Controls.Add(_button);
        a = a + 5;
        v = v + 1;
        whitePanel.Controls.Add(lbl3);
        whitePanel.Controls.Add(lbl4);
        whitePanel.Controls.Add(lbl5);
        whitePanel.Controls.Add(lbl6);
        whitePanel.Controls.Add(lbl7);
        whitePanel.Controls.Add(lbl8);
        whitePanel.Controls.Add(txt1);
        whitePanel.Controls.Add(txt2);
        whitePanel.Controls.Add(txt3);
        whitePanel.Controls.Add(txt4);
        whitePanel.Controls.Add(txt5);
        whitePanel.Controls.Add(cmb4);
        panel1.Controls.Add(whitePanel);
}
以这种方式输出是这样的......通过点击新购买这个带有文本框的多个面板将出现:
这里设置文本框名称的方式对我来说似乎不是更好的方式。我想使用一个数组来设置文本框的名称。
毕竟我想通过使用数组或for循环单击保存按钮将这些值保存到数据库中......但我不知道如何定义它......
谁能帮帮我吗?
并提前感谢