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

  • Home
  • SEARCH
  • 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 3434034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:38:55+00:00 2026-05-18T07:38:55+00:00

I have a sales simulator written in C#. I did not write this however

  • 0

I have a sales simulator written in C#. I did not write this however I am currently modifying it to suit different requirements.

It basically displays a list of products from a database, and has a textbox for each product where you can enter in the quantity sold. The quantity sold is calculated based on it’s price in the database.

Now it’s all working fine, however there is one SMALL issue. When “Buy” is clicked, it returns me back to the list of products which IS correct, however the quantity I have entered for the previous product remains.

I would like to know how to restore the text boxes to their default value when the after the data is submitted to the database.

I always thought the way to do this would be in the .cs code behind file

txtQuantity.Text = "";

However, for some odd reason, txtQuantity will not show up.

Can anyone think of anything I am doing wrong? Here is a snippet of code from the aspx file.

    <form id="form1" runat="server">
    Date:
    <asp:TextBox ID="txtDate" runat="server" />
    Retailer:
    <asp:DropDownList ID="dlStore" runat="server" 
        onselectedindexchanged="dlStore_SelectedIndexChanged" />
    <asp:ListView ID="lbProducts" runat="server">
        <LayoutTemplate>
            <layouttemplate>
 <table border="1" cellpadding="1" style="width:800px">
  <tr style="background-color:#E5E5FE">
   <th>ID</th>
   <th>ProductCode</th>
   <th>Product Title</th>
   <th>RRP $</th>
   <th>Quantity</th>
   <th>Sale Price $</th>
  </tr>
  <tr id="itemPlaceholder" runat="server"></tr>
 </table>
</layouttemplate>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td style="width: 50px;">
                    <%#Eval("ProductID") %>
                </td>
                <td>
                    <%#Eval("ProductCode") %>
                </td>
                <td>
                    <%#Eval("ProductTitle") %>
                </td>
                <td>
                    <%#Eval("USListPrice") %>

                </td>
                <td style="width: 50px;">
                    <asp:TextBox ID="txtQuantity" runat="server" Text="0" />
                </td>
                <td style="width: 50px;">
                    <asp:TextBox ID="txtSalePrice" runat="server" Text="0.00" />
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
    <asp:Button ID="btnBuy" Text="Buy These Items" runat="server" OnClick="btnBuy_Click" />
    <asp:Button ID="btnClear" Text="Clear Existing Sales" runat="server" 
        onclick="btnClear_Click"  />
    </form>

There’s a lot going on in the code behind file and I wouldn’t expect anyone to go through it, but how I collect the data from txtQuantity is done with the following line of code:

Int32 quantity = Int32.Parse(((TextBox)item.FindControl("txtQuantity")).Text);

So what I want to be able to do is set this textbox either to be empty, or back to zero.

Any help is appreciated, thanks.

  • 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-05-18T07:38:56+00:00Added an answer on May 18, 2026 at 7:38 am

    Because that txtQuantity control is within a ListView, there could be any number of instances of that control generated. So you can’t access all of them through a single variable.

    You will need to look through all controls within that ListView (and several levels deep) to find all your txtQuantity controls.

    The same of course for the txtSalePrice control.

    EDIT
    You could find those textboxes with code like (untested)

    public IEnumerable<TextBox> FindTextBoxes(Control parent)
    {
       if (parent == null) yield break;
    
       foreach (Control child in parent.Controls)
       {
          TextBox tb = child as TextBox;
          if (tb != null)
             yield return tb; // found one!
          else
             foreach(TextBox tb in FindTextBoxes(child))
                yield return tb; // found it deeper
       }
    }
    

    and call it like:

    foreach(TextBox tb in FindTextBoxes(lbProducts)
    {
       if (tb.Name == "txtQuantity")
       {
         // found a quantity 
       }
       else if (tb.Name == "txtSalePrice")
       {
         // found the salesprice
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28
I have monthly sales figures stored in separate sheets. I would like to create
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have a function that looks something like this: //iteration over scales foreach ($surveyScales
I have a table that saves some account limits like users. For most rows
I have one table that saves comments for a varied set of content types.
I have a web server which saves cache files and keeps them for 7
I have thread exception handler which saves the exception stack trace and should close
At work we have two competing theories for salts. The products I work on
I have a control that, upon postback, saves form results back to the database.

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.