将gridview文本框值传递给javascript [英] passing gridview textbox value to javascript

查看:69
本文介绍了将gridview文本框值传递给javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个带有文本框模板字段的gridview,在其中插入学生标志,现在我想验证文本框(检查特定纸张的完整标志),这里我需要将文本框的值传递给javascript,以便可以在onkeypress上验证文本框文本框事件我该怎么办..

还是有最好的选择..

Hello all,
I have a gridview with textbox template field where I insert Marks of students, now I want to validate the textbox (checking full marks of particular paper),here I need to pass the value of textbox to javascript so that I can validate textbox on onkeypress event of textbox how i can do so..

Or Is there any best alternative..

推荐答案

Gopal,

试试下面的代码

var grid = document.getElementById(<%= GridName.ClientID%>");
for(var i = 0; i< grid.rows.length; i ++){
var row = grid.Rows.getRow(i);
var ActivityTypeCell = row.getCell(10);
var ActivityTypeDropdown = ActivityTypeCell.getElement().childNodes [0];
var value = row.getCell(cellindex).getElement().childNodes [0] .value
}

将cellindex替换为文本框所在单元格的inddex.

快乐编码
:)
Hi Gopal,

Try the below code

var grid = document.getElementById("<%= GridName.ClientID %>");
for (var i=0; i<grid.rows.length; i++){
var row = grid.Rows.getRow(i);
var ActivityTypeCell = row.getCell(10);
var ActivityTypeDropdown = ActivityTypeCell.getElement().childNodes[0];
var value= row.getCell(cellindex).getElement().childNodes[0].value
}

Replace the cellindex with the inxdex of the cell where the text box lies.

Happy Coding
:)


这里我需要将textbox的值传递给javascript
带文本框模板字段的gridview


在调用每行的RowDataBound方法中,将客户端onkeyup添加到每个文本框.使用FindControl查找文本框,然后添加引用JS方法的onclick属性.

在JS方法中,获取文本框值,然后应用您的逻辑.

像这样的东西:
here I need to pass the value of textbox to javascript
gridview with textbox template field


Add a client side onkeyup to each textbox in a RowDataBound method where each row is called. Find the textbox using FindControl and then add onclick attribute referring a JS method.

In JS method, get the textbox value and then apply your logic.

Something like:
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{  
  TextBox tb = (TextBox)e.Row.FindControl("TextBox1");
  tb.Attributes.Add("onkeyup", "javascript: ValidateMe(this);"); 
}


function ValidateMe(currtextbox)
{
   // Use currenttextbox.value to validate
}


这篇关于将gridview文本框值传递给javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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