用于获取gridview中已选择行的代码 [英] code for getting already selected row in gridview

查看:69
本文介绍了用于获取gridview中已选择行的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gridview包含一个总标记的文本框

在gridview下面我有一个名为txttotal的文本框

例如,gridview中有5行。

如果在总标记中输入一个值,则自动将相同的值显示在txttotal文本框中。

如果输入第二个值,则应在txttotal文本框中显示总共2个txtbox并继续显示。

我的代码是:



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();



它可以工作但是当用户将第一个或前一个文本框值从140更改为160时,新值也会添加到txttotal文本框中,我想替换旧值。如何找到用户是否第二次选择特定行...帮我...


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

推荐答案

您可以尝试以下



在TextChanged事件中迭代所有GridViewRow并对所有txtmarks进行求和,文本框值和最终值应分配给txttotal。





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();







或者您可以使用jQuery从文本框中获取值并使用jQuery选择器进行求和。




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


这篇关于用于获取gridview中已选择行的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆