Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7907149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:17:33+00:00 2026-06-03T11:17:33+00:00

Hello I’m doing a school project and I’m stuck on a problem any help

  • 0

Hello I’m doing a school project and I’m stuck on a problem any help would be great

i have a Shopping Cart Gridview that has a text box quantity where a user can change quantity value for some reason it is not getting the new value just the old value thank you!

<div class="container">
            <h1>Shopping Cart</h1>
            <a href="Default.aspx">&lt; Back to Products</a>
            <br /><br />
        <asp:Label ID="Label2" runat="server" ></asp:Label>
        <asp:Label ID="Label3" runat="server" ></asp:Label>
            <asp:GridView runat="server" ID="gvShoppingCart" AutoGenerateColumns="false" EmptyDataText="There is nothing in your shopping cart." GridLines="None" Width="100%" CellPadding="5" ShowFooter="true" DataKeyNames="ProductID" OnRowDataBound="gvShoppingCart_RowDataBound" OnRowDeleting="grdCart_RowDeleting" >
                <HeaderStyle HorizontalAlign="Left" BackColor="#3D7169" ForeColor="#FFFFFF" />
                <FooterStyle HorizontalAlign="Right" BackColor="#6C6B66" ForeColor="#FFFFFF" />
                <AlternatingRowStyle BackColor="#F8F8F8" />
                <Columns>
                    <asp:BoundField DataField="ProductName" HeaderText="Brand" />
                    <asp:TemplateField HeaderText="Quantity">
                        <ItemTemplate>
                            <asp:TextBox runat="server" ID="txtQuantity" Columns="5" Text='<%# Eval("Quantity") %>'></asp:TextBox><br />                            
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}"  />
                    <asp:BoundField DataField="SubTotal" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <br />
            <asp:Button runat="server" ID="btnUpdateCart" Text="Update Cart" OnClick="btnUpdateCart_Click" /><br />
            <asp:Button ID="btnClose2" runat="server" Text="Close" Width="50px" />
        </div>

The code behind

protected void btnUpdateCart_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gvShoppingCart.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                // 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
                    int productId = Convert.ToInt32(gvShoppingCart.DataKeys[row.RowIndex].Value);
                    Label2.Text = productId.ToString();
                    // Find the quantity TextBox and retrieve the value
                    int quantity = int.Parse(((TextBox)row.Cells[1].FindControl("txtQuantity")).Text);

                    Label3.Text = quantity.ToString();
                    ShoppingCart.Cart.Instance.SetItemQuantity(productId, quantity);
                    BindData();
                }
                catch (FormatException) { }
            }
        }

        mpe2.Show();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:17:35+00:00Added an answer on June 3, 2026 at 11:17 am

    I assume that you’re databinding the GridView also on postbacks. You should do that only when !Page.IsPostBack:

    if(!IsPostBack) BindGrid();
    

    Apart from that, if you use a TemplateField, you should use FindControl to get a reference to your control:

    var txtQuantity = (TextBox)row.FindControl("txtQuantity");
    int quantity = int.Parse(txtQuantity.Text);
    

    Sidenote: You dont need to check for DataControlRowType.DataRow when iterating the GridView rows(unlike in RowCreated or RowDataBound).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have a problem with c# Arrays. I need a array to store
Hello guys can you please help me with this problem. When a simple image
Hello I have a number of crystal reports in my VS2008 project. I am
Hello I have a air for android project going and I am wanting to
Hello I have a problem I have Column data in string format in this
Hello I have a table on which I have denied SELECT privs to a
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello! I would like to extract all citations from a text. Additionally, the name
Hello I have been having trouble with this for a while now. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.