将行添加到表单 [英] Add row to a form
问题描述
我正在创建一个订单表格,其中有两个下拉框,这些下拉框将从数据库中填充以供选择,还有一些文本框需要填写(所有框均水平排列) .我希望能够点击添加" 行"按钮并复制所有下拉菜单和文本框,以再次填写,并在订单中添加另一行.我有以下代码,但在弄清楚如何使其能够执行所需功能时遇到了一些麻烦.
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:
这篇关于将行添加到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!