0

我有一个包含 2 个下拉菜单、2 个文本框和一个按钮的页面。用户将从下拉列表中选择项目,然后在文本框中键入数据。完成后,他们将单击一个按钮以从这些控件中获取信息并填充“订单容器”。他们将能够输入多个“订单”。

  • Gridview 控件会成为这个“订单容器”的路径吗?
  • Gridview 控件允许我插入多条记录吗?
  • Gridview 控件是否允许删除记录?

感谢您的帮助!麦克风

更新:这是我更新gridview的方式:

Protected Sub imgAddOrderItemClick(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgAddOrderItem.Click
    Dim qty As String 'Integer
    Dim type As String
    Dim product As String
    Dim price As Integer
    Dim count As Integer

    count = GridView1.Rows.Count
    type = ddlProductTypes.SelectedItem.ToString
    product = ddlProductFamilies.SelectedItem.ToString
    price = 11
    qty = TextBox10.Text


    ' Populate the datatable with your data (put this in appropriate loop)        
    dr = dt.NewRow        
    dr("Type") = type
    dr("Product") = product
    dr("Qty") = qty
    dr("Price") = price

    ' Add the row
    dt.Rows.Add(dr)

    dt.AcceptChanges()

    GridView1.DataSource = dt 'GetData()
    GridView1.DataBind()

End Sub
4

2 回答 2

0

GridView 很好!

你的 dt 来自哪里?

我认为问题在于,当您回发时,您的 dt 会被初始化,因此它是空的。这就是为什么您每次只能获得一个(新)记录。有两种排序方式,

(1)。您必须在会话中保留 dt(或数据源),并且您的代码很好。

(2)。如果 dt 不在会话中,则需要先循环遍历 gridview 行和列以填充已添加的数据(如果有),然后添加新订单并最终将其绑定到 gridview。

希望有帮助!

于 2013-02-28T20:39:03.077 回答
0

Gridview 可以正常工作。您最有可能看到您的行被覆盖,因为您dt的代码中的数据表 ( ) 在每次请求时都会被重新实例化。您需要做的是将该表保存在内存中(例如,将其放在 Session 中),从那里抓取它,添加新行并重新绑定 GridView。像这样的东西:

Protected Sub imgAddOrderItemClick(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgAddOrderItem.Click
dt = Session("Data")

  If dt is Nothing Then
    ' Create your DT columns here
      Session.Add("Data",dt)
  End If

  'Add rows here and rebind
  dr = dt.NewRow        
  dr("Type") = type
  dr("Product") = product
  dr("Qty") = qty
  dr("Price") = price

  ' Add the row
  dt.Rows.Add(dr)

  dt.AcceptChanges()

  GridView1.DataSource = dt 'GetData()
  GridView1.DataBind()
End Sub
于 2013-02-28T20:40:27.013 回答