troubleshooting Question

ItemCommand not getting the correct value in DataGrid

Avatar of lawso
lawsoFlag for Australia asked on
ASP.NET
13 Comments1 Solution768 ViewsLast Modified:
I am trying to get the value of a DataGrid and using an ItemCommand update the value in the DataTable behind it.

I have this working but it sends the OLD value of the txQTY textbox.

Can someone help?

DATAGRID
<asp:DataGrid id="dg" runat="server" AutoGenerateColumns="False" BorderStyle="None" BorderWidth="1px" BorderColor="#3366CC" BackColor="White" CellPadding="4" OnDeleteCommand="dg_DeleteCommand" OnItemCommand="dg_ItemCommand">

                <FooterStyle forecolor="#003399" backcolor="#99CCCC"></FooterStyle>

                <HeaderStyle font-bold="True" forecolor="#CCCCFF" backcolor="#003399"></HeaderStyle>

                <PagerStyle horizontalalign="Left" forecolor="#003399" backcolor="#99CCCC" mode="NumericPages"></PagerStyle>

                <SelectedItemStyle font-bold="True" forecolor="#CCFF99" backcolor="#009999"></SelectedItemStyle>

                <ItemStyle forecolor="#003399" backcolor="White"></ItemStyle>

                <Columns>

                    <asp:TemplateColumn HeaderText="Product Name">
                        <ItemTemplate><asp:label id="Product_Name" text='<%# databinder.eval(container.dataitem, "Product_Name") %>'  runat="server"></asp:label></ItemTemplate>
                    </asp:TemplateColumn>

                    <asp:TemplateColumn HeaderText="Price">
                        <ItemTemplate>$<asp:label id="Product_Price" text='<%# databinder.eval(container.dataitem, "Product_Price") %>'  runat="server"></asp:label></ItemTemplate>
                    </asp:TemplateColumn>

                    <asp:TemplateColumn HeaderText="Size">
                        <ItemTemplate><asp:label id="Product_Size_Text" text='<%# databinder.eval(container.dataitem, "Product_Size_Text") %>'  runat="server">
                        </asp:label></ItemTemplate>
                    </asp:TemplateColumn>
                                       
                    <asp:TemplateColumn HeaderText="Colour">
                        <ItemTemplate><asp:label id="Product_Colour_Text" text='<%# databinder.eval(container.dataitem, "Product_Colour_Text") %>'  runat="server"></asp:label></ItemTemplate>
                    </asp:TemplateColumn>
                   
               

                    <asp:TemplateColumn HeaderText="QTY">

                        <ItemTemplate>
                   
                            <EditItemTemplate>

                                <asp:TextBox id="txtQTY" text='<%# databinder.eval(container.dataitem, "Quantity") %>' maxlength="2" width="30" runat="server"></asp:TextBox>

                            </EditItemTemplate>

                        </ItemTemplate>

                    </asp:TemplateColumn>

                    <asp:TemplateColumn HeaderText="Amount">
                    <ItemTemplate>
                   
                    <!--HIDDEN STUFF-->
                    <asp:label id="Gst_Excluded" text='<%# databinder.eval(container.dataitem, "Gst_Excluded") %>'  runat="server" Visible="false"></asp:label>
                    <asp:label id="Product_Size" text='<%# databinder.eval(container.dataitem, "Product_Size") %>'  runat="server" Visible="false"></asp:label>
                    <asp:label id="Product_Colour" text='<%# databinder.eval(container.dataitem, "Product_Colour") %>'  runat="server" Visible="false"></asp:label>
                    </ItemTemplate>
                   
                    </asp:TemplateColumn>

                    <asp:ButtonColumn Text="Remove" CommandName="Delete"></asp:ButtonColumn>
                    <asp:ButtonColumn Text="Re-Calculate" CommandName="Recalculate"></asp:ButtonColumn>

                </Columns>

            </asp:DataGrid>

ITEMCOMMAND
Protected Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        Select Case e.CommandName
            Case "Recalculate"
                'Dim newQTY As Integer = CType(e.Item.FindControl("txtQTY"), TextBox).Text
                Dim newQTY As Integer = CType(e.Item.FindControl("txtQTY"), TextBox).Text
                Response.Write(newQTY)
               

                shopping_cart.AddToCart(Me.txtPRODID.Text, Me.txtPRODNAME.Text, Me.txtPRODPRICE.Text, Me.ddlSIZES.SelectedItem.Text, Me.ddlSIZES.SelectedValue, Me.ddlCOLOURS.SelectedItem.Text, Me.ddlCOLOURS.SelectedValue, newQTY, Me.txtGST_INCLUDED.Text)
                If Page.IsPostBack = True Then
                    dg.DataBind()
                End If
        End Select
       
    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros