将行添加到表单 [英] Add row to a form

查看:103
本文介绍了将行添加到表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个订单表格,其中有两个下拉框,这些下拉框将从数据库中填充以供选择,还有一些文本框需要填写(所有框均水平排列) .我希望能够点击添加" 行"按钮并复制所有下拉菜单和文本框,以再次填写,并在订单中添加另一行.我有以下代码,但在弄清楚如何使其能够执行所需功能时遇到了一些麻烦.

I am in the process of creating an order form where I have a couple of drop-down boxes that will be populated from a database to select from and text boxes that need to be filled in (all horizontally alighned). I would like to be able to click an "add row" button and duplicate all of the drop-downs and text boxes to be filled in again and add another line to the order. I have the following code, but I am having a little trouble figuring out how I would make it do what I need.

        protected void addNewRow()
        {
            // Get Row Count
            int currentRowCount = 3;

            // Add 1 to row count
            string newRowCount = Convert.ToString(currentRowCount++);

            lblErrorMessage.Visible = true;
            lblErrorMessage.Text = "Row Count: " + newRowCount;

            try
            {
                // Add button
                //Button btnSave = new Button();
                //pnlTest.Controls.Add(btn);

                TextBox txtDescription = new TextBox();
                txtDescription.ID = "txtDescription" + newRowCount;
                pnlTest.Controls.Add(txtDescription);
            }
            catch (Exception ee)
            {
                // Add row error
                lblErrorMessage.Text = ee.Message.ToString();
            }
        }



推荐答案

如果您使用的是ASP c#,则此问题可能会对您有所帮助:

If you're using ASP c# this question may help you:

如何动态生成TextBox控件.


这篇关于将行添加到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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