在ASP.NET中,可以使用动态表单来动态生成表单元素,然后使用SQL Server来存储和检索表单数据。以下是一个简单的代码示例,演示如何实现动态表单。
protected int fieldCount = 0;
protected void btnAddField_Click(object sender, EventArgs e)
{
fieldCount++;
TextBox txtField = new TextBox();
txtField.ID = "txtField" + fieldCount;
pnlFields.Controls.Add(txtField);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (Control control in pnlFields.Controls)
{
if (control is TextBox)
{
TextBox txtField = (TextBox)control;
string fieldValue = txtField.Text;
// 将fieldValue插入到SQL Server数据库中
// ...
}
}
}
请注意,上述代码示例只是一个基本的框架,您可能需要根据您的具体需求进行适当的修改和调整。另外,插入数据到SQL Server数据库的代码部分还需要根据您的数据库架构和连接方式进行相应的处理。