access data in textfied in gridview
im working on a shopping cart i have a gridview that loop throuh all record in the database and display on the gridview i add two extra column one for a link when user click on the link it add the product in the shopping cart the other column is a textfield which user should enter the quantity of the item they want to purchase here is my problem i can get the value user enter in the textfield can someone please give me some direction thank you
Aspx page
<asp:GridView ID="grdProducts" runat="server">
开发者_C百科 <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>
Code behind the page
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
how can i fetch data in (textfield id =tbQty)
http://aspdotnet-example.blogspot.com/2011/04/gridview-data-control-in-aspnet-example.html
in that GridView.ASPX.cs page give you result
精彩评论