Web ページのドロップダウンを変更するたびに、ページが「リセット」されます。プログラムで挿入した行が消え、新しい行が書き込まれます。ユーザーが複数の行を追加できるようにしたい。
私はしようとしています
- ドロップダウンを使用して、製品情報を表示する複数の GridView に入力します
- ユーザーはテキストボックスに数量を追加します
- 「カートに入れる」をクリックすると...
- 選択した製品の詳細を使用して、そのページの既存のテーブルに新しい行を作成します
これは最初の行でのみ正常に機能しますが、ドロップダウンを変更するか、[カートに追加] ボタンをクリックすると、新しく挿入された行が後続の更新からの行によって上書きされます。
これは私のテーブルです...
<asp:Table ID="tblOrderPreview" runat="server" BorderStyle="Solid" Width="800px" >
<asp:TableHeaderRow BorderStyle= "Solid"><asp:TableHeaderCell>Product</asp:TableHeaderCell><asp:TableHeaderCell>Qty</asp:TableHeaderCell><asp:TableHeaderCell>Price</asp:TableHeaderCell><asp:TableHeaderCell>Total</asp:TableHeaderCell><asp:TableCell><b>Remove Item</b></asp:TableCell></asp:TableHeaderRow>
<asp:TableRow BorderStyle= "Solid"><asp:TableCell></asp:TableCell><asp:TableCell></asp:TableCell><asp:TableCell></asp:TableCell><asp:TableCell></asp:TableCell><asp:TableCell></asp:TableCell></asp:TableRow>
</asp:Table>
そして、これはボタンが呼び出すコードです:
Protected Sub btnAddToCart_Click(sender As Object, e As System.EventArgs) Handles btnAddToCart.Click
lblValidator.Visible = False
If txtQuantity.Text <> "" Then
lblValidator.Visible = False
Dim name As String
name = GridView3.Rows(0).Cells(0).Text.ToString
Dim qantity As Integer
qantity = Convert.ToDouble(txtQuantity.Text)
Dim price As String
price = Convert.ToDouble(GridView5.Rows(0).Cells(0).Text.ToString)
Dim total As String
total = "$" + (price * qantity).ToString
'insert new row to tblOrderPreview (count rows, then insert another row named COUNT+1
Dim tRow As New TableRow()
tblOrderPreview.Rows.Add(tRow)
Dim tCellProduct As New TableCell()
tCellProduct.Text = name
tRow.Cells.Add(tCellProduct)
Dim tCellQty As New TableCell()
tCellQty.Text = qantity.ToString
tRow.Cells.Add(tCellQty)
Dim tCellPrice As New TableCell()
tCellPrice.Text = price
tRow.Cells.Add(tCellPrice)
Dim tCellTotal As New TableCell()
tCellTotal.Text = total
tRow.Cells.Add(tCellTotal)
Dim tCellRemove As New TableCell()
tCellRemove.Text = "del!"
tRow.Cells.Add(tCellRemove)
Else
lblValidator.Visible = True
End If
End Sub