在我的gridview中,我列出了一堆來自數據庫的由存儲過程加載的產品。 所以在GridView我列出即產品名稱,價格,描述等,但後來我有一個名爲數量文本框,用戶可以在量輸入,當他們按更新然後我在我的購物車插入此作爲cartitemASP.NET從ShoppingCart的會話變量中填充GridView中的文本字段
Protected Sub btnUpdateCart_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdateCart.Click
For Each row As GridViewRow In gvShoppingCart.Rows
If row.RowType = DataControlRowType.DataRow Then
' We'll use a try catch block in case something other than a number is typed in. If so, we'll just ignore it.
Try
' Get the productId from the GridView's datakeys
Dim productId = Convert.ToInt32(gvShoppingCart.DataKeys(row.RowIndex).Value)
' Find the quantity TextBox and retrieve the value
Dim quantity = Integer.Parse(CType(row.Cells(1).FindControl("txtQuantity"), TextBox).Text)
ShoppingCart.Instance.SetItemQuantity(productId, quantity)
Catch ex As FormatException
End Try
End If
Next
BindData()
End Sub
因此,當我在頁面之間滑動時,例如shoppingcart.aspx和checkout.aspx,我鬆開了在這些複選框中輸入的值,所以我期待的是每次使用gridview加載頁面時都要檢查對於我的會議shoppingcart,並查看產品ID是否與行和會話匹配,如果他們確實在文本框中動態輸入該數量。我的繼承人的GridView
<asp:GridView runat="server" ID="gvShoppingCart" AutoGenerateColumns="false" EmptyDataText="There is nothing in your shopping cart." AlternatingRowStyle-CssClass="tr_dark" HeaderStyle-CssClass="header_req" BorderWidth="0px" GridLines="None" AllowPaging="true" PageSize="25" AllowSorting="false" Width="100%" ShowFooter="true" DataKeyNames="ProductId" OnRowDataBound="gvShoppingCart_RowDataBound" OnRowCommand="gvShoppingCart_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Product Name" HeaderStyle-Width="130px" SortExpression="productName">
<ItemTemplate>
<asp:Label ID="ProductNameField" runat="server" Text='<%# Eval("description").ToString() %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Pack Size" HeaderStyle-Width="70px" SortExpression="packSize">
<ItemTemplate>
<asp:Label ID="PackSizeField" runat="server" Text='<%# Eval("packSize").ToString()%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Stock" HeaderStyle-Width="130px" SortExpression="address">
<ItemTemplate>
<asp:Label ID="TradePriceField" runat="server" Text='<%# DisplayStockLevel(Eval("StockIndicator").ToString()) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Quantity" HeaderStyle-Width="10px">
<ItemTemplate>
<asp:TextBox runat="server" Width="30" ID="txtQuantity" Text='<%# Eval("Quantity") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:BoundField DataField="UnitPrice" HeaderText="Actual Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
<asp:BoundField DataField="TotalPrice" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
</Columns>
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/img/icons/cross.gif" width="10" height="10" alt="Cancel" runat="server" ID="btnRemove" CommandName="Remove" CommandArgument='<%# Eval("ProductId") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
你能解釋我怎麼能從SP的結果集中創建產品的包裝? – StevieB
我會在上面的帖子中解釋 – Parvesh