表格行在Dropdown ItemSelected上消失

时间:2013-06-11 11:06:39

标签: asp.net vb.net visual-studio

每次我更改网页上的下拉菜单时,页面都会“重置”。我以编程方式插入的一行消失,并写入一个新行。我想让用户添加多行。

我正在尝试

  1. 使用下拉列表填写显示产品信息的多个GridView
  2. 用户将在文本框中添加数量
  3. 点击“添加到购物车”,这将...
  4. 在该页面上现有表上创建一个新行,其中包含所选产品详细信息
  5. 这仅适用于第一行,但是,如果我更改下拉列表或单击“添加到购物车”按钮,则新插入的行将被后续更新中的行覆盖。

    这是我的表...

    <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
    

1 个答案:

答案 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