如何从客户端检查网格视图中的行 [英] How do I check Rows in Grid View from Client Side

查看:62
本文介绍了如何从客户端检查网格视图中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

我想从客户端检查网格视图中的行数。像文本框一样。例如

 < script    < span class =code-attribute> language   =  javascript   类型  =  text / javascript >  
函数IsValid()
{
var fname = document.getElementById( <%= txtFName.ClientID%>). value ;
if (fname ==
{
alert( 请输入名称);
document.getElementById( <%= txtFName.ClientID%>)。焦点();
return false ;
}
}
< / script >

解决方案





在客户端,网格视图是一个html表。



在JavaScript中,要获取html表上的行数,你需要检查表格的长度行集合



使用其ClientID属性访问您的GridView,并且您有对html表的引用。



这样的事情应该有效:

  var  gridViewRowCount =  document  .getElementByID(' <%= gv.ClientID%>')。rows.length; 





...希望它有所帮助。






参考:

1)使用javascript进行Gridview行计数

2)如何使用jQuery在asp.net中对gridview中的行进行计数


您需要先创建链接对象,然后为其添加属性。检查下面的代码 -



  foreach (GridViewRow row >  gv1.Rows)
{
// 在gridView行中创建按钮对象
按钮btnRowCommand =(按钮)row.FindControl( YourButtonName);
// 将属性添加到buttonng =sql>按钮 - 在这种情况下添加onclick属性
// 将触发
// gv1RowCommand(ID); javascript函数
btnRowCommand.Attributes.Add( onclick gv1RowCommand(' + ID + < span class =code-string>');
);
}

函数gv1RowCommand(ID){
alert(' 行命令测试');
}


Dear Sir,
I want to check No.of Rows in Grid View from Client Side. Like Text Box. Ex.

<script language="javascript" type="text/javascript">
function IsValid()
{
 var fname=document.getElementById("<%=txtFName.ClientID%>").value;
 if(fname=="")
 {
   alert("Please Enter Name");
   document.getElementById("<%=txtFName.ClientID%>").focus();
   return false;
 }
}
</script>

解决方案

Hi,

On the client side, a grid view is an html table.

In JavaScript, to get the number of rows on an html table, you would check the length of the tables row collection.

Access your GridView using its ClientID property, and you have a reference to your html table.

Something like this should work:

var gridViewRowCount=document.getElementByID('<%=gv.ClientID%>').rows.length;



... Hope it helps.


Hi,

Ref this:
1) Gridview row count using javascript.
2) How to count the rows in a gridview in asp.net using jQuery


You need to create object of your link first and then add attributes to it. check below code -

foreach (GridViewRow row in gv1.Rows)
 {
    //Creates object of button inside your gridView Row
    Button btnRowCommand = (Button)row.FindControl("YourButtonName");
    //Adds Attribute to buttonng="sql">button - in this case adds onclick attribute
    //which will fire the
    //gv1RowCommand(ID); javascript function
    btnRowCommand.Attributes.Add("onclick", "gv1RowCommand('"+ ID +"');");
 }

function gv1RowCommand(ID) {
alert('Row command test');
}


这篇关于如何从客户端检查网格视图中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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