Click here to Skip to main content
13,551,917 members
Rate this:
Please Sign up or sign in to vote.
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 :

if (gridviewrowcount == 0)
                txttotal.Text = totalmarks.Text;
               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 21:10pm
Updated 1-Apr-13 21:28pm

1 solution

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180515.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2018
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