查找gridview的子控件ID [英] find child control id of gridview

查看:75
本文介绍了查找gridview的子控件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在asp.net中开发一个项目,并在gridview中使用带有三个文本框的三个模板字段.如何获取子控件ID(文本框ID)以获取前两个文本框的值,并在最后一个文本框中设置这两个文本框的加法?我需要为每一行的每个文本框使用单独的ID.

Hi,
I am developing a project in asp.net and use three template fields with three textboxes in gridview. How can I get the child control id(textbox id)for getting values of first two textboxes and set addition of these two textbox in last textbox? I am required to use separate id''s for each textbox for each row. How can this be done by using javascript?

推荐答案



您可以使用javascript函数解决以下问题.
Hi,

you can solve above issue as follows by using javascript function.
function AddValues(obj)
{
     var tr=obj.parentNode.parentNode; //finding current entered row.
     var txt1=tr.cells[0].getElementByTagName("INPUT")[0];//first textbox
     var txt2=tr.cells[1].getElementByTagName("INPUT")[0];//second textbox
     var txt3=tr.cells[2].getElementByTagName("INPUT")[0];//third textbox
     txt3.value=parseInt(txt1.value) +  parseInt(txt2.value);
}


在此根据您的要求使用适当的单元格索引值.
在每个文本框中的onkeypress事件中调用上述函数,如下所示:

onkeypress="javascript:return AddValues(this);";


问候,
基兰.


Here use the proper cell index value based on your requirement.
Call the above function in the event of onkeypress in every Textboxes as follows:

onkeypress="javascript:return AddValues(this);";


Regards,
Kiran.


这篇关于查找gridview的子控件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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