简体   繁体   English

表单行后面的ASP.NET代码

[英]ASP.NET Code behind form rows

I'm trying add multiple items to a database table. 我正在尝试将多个项目添加到数据库表中。 I've created a form that will allow the user to add more form rows which include a dropdown and multiple input fields. 我创建了一个表单,该表单将允许用户添加更多表单行,其中包括一个下拉列表和多个输入字段。 New fields are generated when the user clicks on "+". 当用户单击“ +”时,将生成新字段。 This is developed using JavaScript. 这是使用JavaScript开发的。

It is easy to add an incremented value to an ID using JavaScript, but new rows are not made using the runat="server" so I am afraid my code behind won't see the values in the fields. 使用JavaScript向ID添加增量值很容易,但是不会使用runat="server"来创建新行,因此我担心后面的代码在字段中看不到这些值。

I want my code to loop through each form "row" and grab each item. 我希望我的代码遍历每个表单“行”并获取每个项目。 Then take this data and insert it into a SQL database. 然后获取这些数据并将其插入到SQL数据库中。 How do I get that working? 我该如何工作? 在此处输入图片说明

I can give you some guides to continue from the point you are (and solve this question - so I am afraid my code behind won't see the values in the fields.) 我可以为您提供一些指导,从您的角度出发(并解决此问题-恐怕我后面的代码看不到字段中的值。)

a . 一个 You create your controls using java-script on the page. 您可以在页面上使用Java脚本创建控件。
b . b User then is post them back, what you have all ready known, with some new controls that code behind didn't know about. 然后,用户将它们放回去,这些都已经众所周知,并带有一些后面的代码不知道的新控件。

now the trick here is that you grab this return 现在的诀窍是,您将获得此回报

HttpContext.Current.Request.Form

and analyse it to see whats "is new there", what are the new post controls that you don't know about - and then you create them on code behind again - and gets their input values. 并对其进行分析,以了解什么是“那里的新内容”,哪些是您不知道的新post控件-然后您在后面的代码中再次创建它们-并获取它们的输入值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM