Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my gridview consist of a textbox of totalmarks
below gridview i have an textbox named txttotal
for an eg, there are 5 rows in gridview.
if a value is entered in totalmarks, automatically same value should get displayed in txttotal textbox.
if 2nd value is entered total of 2 txtboxes should beg displayed in txttotal textbox and it goes on.
My code is :

C#
if (gridviewrowcount == 0)
                txttotal.Text = totalmarks.Text;
            else
               txttotal.Text = (Convert.ToDouble(txttotal.Text) + Convert.ToDouble(totalmarks.Text)).ToString();

It works but when user changes the first or previous textbox value from 140 to 160, then new value also gets added in txttotal textbox, i want to replace the old value. how to find if user is selecting the particular row for 2nd time.. help me...
Posted
Updated 1-Apr-13 21:28pm
v2

1 solution

You can try with below

On TextChanged Event Iterate through all GridViewRow and do summation of all txtmarks textbox value and final value should be assigned to txttotal.


C#
double sum = 0;
                foreach (GridViewRow item in GridView1.Rows)
                {
                    var txt = item.FindControl("txtmarks") as TextBox;
                    sum += Convert.ToDouble(txt);
                }

                txttotal.Text = sum.ToString();



or you can use jQuery to get values from textbox and do summation using jQuery selectors.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900