0

Having problem writing form data to database.a form that creates multiple rows on the fly
by cloning form controls and incrementing textboxes name and id properties.but when i post form only the first line get written to database.

 var ind = Request.Form.Count;

foreach(int i = 0; i < ind; i++){ 
   if (IsPost)
 {
       Item_No = Request.Form.Item_No[i];
       Item_Desc = Request.Form.Item_Desc[i];
       Qty = Request.Form.Qty[i];
       var db = Database.Open("s2k");
       var insertQuery = "INSERT INTO OrderItems" +
      "(Item_No, Item_Desc, Qty)" +
      "Values (@0, @1, @2)";
       db.Execute(insertQuery, Item_No, Item_Desc, Qty);
       Response.Redirect("~");
   }
  }

adds new form elements

function addTableRow(table)
            {
            var $tr = $(table).find("tbody tr:last").clone();               
            $tr.find("input,select").val('').attr("name", function()
    {      
      var parts = this.id.match(/(\D+)(\d+)$/);

      return parts[1] + ++parts[2];   
    }).attr("id", function(){
            var parts = this.id.match(/(\D+)(\d+)$/);
            return parts[1] + ++parts[2];
                });             
                $(table).find("tbody tr:last").after($tr);
            };

form

<form method="post" id = "form" title= "form">
            <table>             
                  <thead>
           <tr>
            <th class="product">Item_No</th>
            <th class="size">Item_Desc</th>
            <th class="price">Qty</th>
           </tr>

                </thead>
                <tbody>
                        <td><input type="text" name="Item_No" id="Item_No1"></td>
                        <td><input type="text" name="Item_Desc" id="Item_Desc1"></td>
                        <td><input type="number" name="Qty" id="Qty1"></td>
                    </tr>
                </tbody>
            </table>

            <p><input type="submit" name="buttonSubmit" value="Create Order" /></p>
    </form>
4

1 回答 1

0

在我看来,这条线是你的问题:

  Response.Redirect("~");

你已经在你的循环中得到了它,所以在第一次循环结束时,它会执行,另一个页面将开始加载。你的循环永远不会结束。

于 2013-03-01T19:25:23.937 回答