0

データベースへのフォーム データの書き込みに問題が
あります。フォーム コントロールのクローンを作成し、テキスト ボックスの名前と ID プロパティをインクリメントすることで、その場で複数の行を作成するフォームですが、フォームを投稿すると、最初の行だけがデータベースに書き込まれます。

 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("~");
   }
  }

新しいフォーム要素を追加します

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 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 に答える