2013-02-27 230 views
0

我有一个包含2个下拉菜单,2个文本框和一个按钮的页面。用户将从下拉列表中选择项目,然后将数据输入到文本框中。这样做后,他们将点击一个按钮,从这些控件中获取信息并填充“订单容器”。他们将能够输入多个“订单”。这种情况下的哪种控制?

  • Gridview控件是否会成为这个“Order Container”的路线?
  • 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 
+0

我不认为'GridView'允许你插入记录。您最好查看['ListView'](http://msdn.microsoft.com/zh-cn/library/bb398790%28v=vs.100%29.aspx)控件。 – 2013-02-27 21:12:28

+0

我已经能够添加一行到Gridview,但只有一行。如果我有第二行,它会覆盖现有的行。 – Charlie 2013-02-28 20:21:42

+0

我正在添加一个像这样的新行: Charlie 2013-02-28 20:22:49

回答

0

的GridView是罚款!

你的DT从哪里来?

我认为问题是,当你回来后,你的dt被初始化,因此它是空的。这就是为什么你每次只能得到一个(新)记录。有两种方法可以对它进行分类,

(1)。你必须保持dt(或数据源)在你的会话中,你的代码是好的。

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

希望有帮助!

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 
+0

谢谢。我需要阅读会话和会话变量。看到我上面的更新。 – Charlie 2013-02-28 20:57:16