0

Hello Everyone,
I am create a shopping application. I have load all products to gridview with a button with rowcommand event. When I click on add cart button the current row will be add to a object of girdview row. Now how will i get value of qty which is a text box place in grid.

<asp:GridView ID="grdProdctInfo" runat="server" AllowPaging="true" 
                                                AllowSorting="true" 
                                                AutoGenerateColumns="false"
                                                CssClass="gridview"
        BorderStyle="Groove" GridLines="None" Width="619px" EnableViewState="false" Enabled="false">
        <Columns>
            <asp:BoundField DataField="ProductName" HeaderText="Product Name" />
            <asp:BoundField DataField="StockInHand" HeaderText="Available Stock" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="10px" />
            <asp:BoundField DataField="MSRPCA" HeaderText="Price" ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="10px" />
                        
            <asp:TemplateField HeaderText="Picture" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="20px">
                <ItemTemplate>
                    <asp:Image runat = "server" ID = "grdImage" ImageUrl='<%#DirectCast(FormatImageUrl(DirectCast(Eval("PictureLocation"), String)), String) %>' Width="60px" Height="60px" />
                </ItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Purchase Quantity" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10px">
                <ItemTemplate>
                    <asp:TextBox runat="server" ID="QunantityTextBox" Width="30px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField ItemStyle-HorizontalAlign="Right" ItemStyle-Width="69px">
                <ItemTemplate>
                    <asp:ImageButton ID = "AddToCartButton" CommandName="AddToCart" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
 runat="server" ImageUrl="~/Images/cart1.png" Width="80px" />
                </ItemTemplate>
            </asp:TemplateField>
            
            
        </Columns>
        <EmptyDataTemplate>
            Sorry! your required product not found. Please feel free to contact us for any query.
        </EmptyDataTemplate>
        
    </asp:GridView>
Protected Sub grdProdctInfo_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdProdctInfo.RowCommand
        If e.CommandName = "AddToCart" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            row = grdProdctInfo.Rows(index)
            Response.Write(row.Cells(5).Text)
        End If

    End Sub
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by guru_sarkar
0

What is the exact problem?
In the RowCommand method you can do a FindControl for the Quantity TextBox and get/set the test like:

Dim tb As TextBox = DirectCast(row.FindControl("QunantityTextBox"),TextBox)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.