2011-06-21 85 views
0

即時通訊工作在購物車我有一個gridview循環通過數據庫中的所有記錄,並顯示在gridview我添加兩個額外的列一個鏈接時,用戶點擊鏈接添加產品在購物車的其他欄是一個文本框,用戶應該輸入他們想要購買的物品的數量在這裏是我的問題,我可以得到的價值用戶在文本框中輸入可以有人請給我一些方向謝謝訪問gridview中的數據


ASPX頁面

<asp:GridView ID="grdProducts" runat="server"> 

      <Columns> 
       <asp:ButtonField CommandName="AddToCart" HeaderText="Add To Cart" Text="Add To Cart" /> 

       <asp:TemplateField HeaderText="Qty"> 
      <ItemTemplate> 
       <asp:TextBox ID="tbQty" runat="server" Width="25px" 
        MaxLength="3" /> 
        </ItemTemplate> 
         <ItemStyle Width="25px" HorizontalAlign="Center"/> 
          </asp:TemplateField> 


      </Columns> 


     </asp:GridView> 

頁面

Private Sub grdProducts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdProducts.RowCommand 

     Dim intRowSelected As Integer = -1 
     Dim strProductName As String = "" 

     Try 

      intRowSelected = e.CommandArgument 
      strProductName = grdProducts.Rows(e.CommandArgument).Cells(2).Text 
      AddItemToCart(strProductName) 



      Dim rowIndex As Integer 

      If Integer.TryParse(e.CommandArgument.ToString(), rowIndex) Then 

       Dim c As Control = grdProducts.Rows(rowIndex).FindControl("tbQty") 
       If TypeOf c Is TextBox Then 
        Response.Write(DirectCast(c, TextBox).Text) 
        PlaceHolder1.Controls.Add(c) 
       End If 
      End If 


     Catch ex As Exception 
      Debug.WriteLine(ex.Message) 
     End Try 

    End Sub 

我如何可以獲取在(文本域ID = tbQty)

回答