每次我更改网页上的下拉菜单时,页面都会“重置”。我以编程方式插入的一行消失,并写入一个新行。我想让用户添加多行。
我正在尝试
这仅适用于第一行,但是,如果我更改下拉列表或单击“添加到购物车”按钮,则新插入的行将被后续更新中的行覆盖。
这是我的表...
<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
答案 0 :(得分:1)
只是为了澄清我上面的评论并展示一些代码:
Dim tblRowColl As TableRowCollection = tblOrderPreview.Rows
'Run the code that gets the new row
For Each tblRow As TableRow In tblRowColl
tblOrderPreview.Rows.Add(tblRow)
Next
希望这有帮助。
谢谢,
Firstcape