?
Solved

Adding values of a column when checkbox is clicked

Posted on 2013-01-13
2
Medium Priority
?
329 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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