Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 :
 
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 1-Apr-13 22:10pm
Edited 1-Apr-13 22:28pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 385
1 Sergey Alexandrovich Kryukov 329
2 CPallini 270
3 DamithSL 214
4 Maciej Los 192
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100