Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding values of a column when checkbox is clicked

Posted on 2013-01-13
2
Medium Priority
?
330 Views
Last Modified: 2013-01-13
I have been at this for a week and still cant figure it  out. I have a listview with a checkbox column and another column with a price. When user checks a checkbox, i want to add the values and when they deselect...i want to decrement the value. I still cant get thos going...

If there are previous rows that user has checked and paid...i have those checkboxes disbaled so I dont add those rows

Each row is $50 (as an example)

Issue I have now is : I click a checkbox, code loops thru the rows and value is $50. This is correct. I check another checkbox...code loops and now the value is $150...this is because first check has the field as 50, then it loops and i have 2 checkboxes so that's 100 for total of 150...it should be 100 not 150

 <asp:CheckBox runat="server" AutoPostBack="true" OnCheckedChanged="onCheckChange_chkSelect"    ID="chkSelect" />

 if (!Page.IsPostBack)
        {
           x_amount.Text = "0";
       }

protected void onCheckChange_chkSelect(object sender, EventArgs e)
    {
              //add and decrement total
        foreach (var provider in lvPayment.Items)
        {
            CheckBox providerChecked = (CheckBox)provider.FindControl("chkSelect");
            Label price = (Label)provider.FindControl("lblPrice");
            Label paid = (Label)provider.FindControl("lblSubsDate");
           //paid.text means this user hasnt paid and based on that...the checkbox is enabled
          //if checkbox is disabled, dont add that value to the amount
            if (providerChecked.Checked && paid.Text == string.Empty && providerChecked.Enabled)
                x_amount.Text = (int.Parse(x_amount.Text) + int.Parse(price.Text)).ToString();
            else
                if (!providerChecked.Checked && paid.Text == string.Empty)
                   x_amount.Text = (int.Parse(x_amount.Text) - int.Parse(price.Text)).ToString();


        }

    }

Open in new window

0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 38772866
Maybe I'm missing something. What if you set x_amount.Text = "0"; on every postback then loop through, skip the test for "Enabled", skip the "else" and just add everything that is checked?
0
 
LVL 7

Author Comment

by:Camillia
ID: 38772948
you're totally correct. Let me try it.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question