简体   繁体   English

如何使用javascript遍历gridview的列?

[英]How to traverse a column of a gridview using javascript?

I have a gridview that is binded dynamically on run time. 我有一个在运行时动态绑定的gridview。 I need to traverse a column of gridview on client side. 我需要在客户端遍历一列gridview。 I have passed the id of gridview to the javascript function but I have no clue as how to traverse a particular row. 我已经将gridview的ID传递给javascript函数,但是我不知道如何遍历特定行。

I m calling the javascript function from my code behind as - 我正在从我的代码后面调用javascript函数-

btnInsert.Attributes.Add("OnClick", "return IsValidEntry(" + gridview.ClientID + ")");

right now I m catching ID of the control of a particular row and passing it to another javascript function as - 现在我正在捕获特定行的控件的ID,并将其传递给另一个javascript函数,例如-

function IsValidEntry(Status) 
    {
        var strErr='';
        if(document.getElementById(Status.id).innerHTML == "Dev in Progress")
        {
            strErr+='<br>* Develeopment should be completed first.';
            document.getElementById('schValidation').innerHTML = strErr;                
            jQuery("#schValidation").show('slow');
            return false;
        }
    }

Which is working fine.but now I need to traverse this whole column. 很好,但是现在我需要遍历整个专栏。

A link or some sample code will be very helpful. 链接或一些示例代码将非常有帮助。

Thanks 谢谢

Akhil 阿基尔

I would suggest using jquery. 我建议使用jQuery。 Give the column a CSS class and use the each iterator. 给该列提供一个CSS类,并使用每个迭代器。

    $(function() {
        $('.className').each(function () {
            // do something...
        });
    });

Using JQuery you can traverse your gridview rows and column like this 使用JQuery,您可以像这样遍历gridview的行和列

$(document).ready(function () {
            $('#GridViewID tr').each(function () {
                alert($(this).find("td:eq(0)").text()); //get column1 value
                alert($(this).find("td:eq(1)").text()); //get column2 value
            });
        });

I solved it by - 我通过-解决了

function IsValidEntry() 
      {
        var len = document.getElementById('ctl00_ContentPlaceHolder1_gdScheduleNew').rows.length;
        var i;
        for (i = 2; i <= len; i++) 
        {
            if(document.getElementById("ctl00_ContentPlaceHolder1_gdScheduleNew_ctl0" + i + "_lblStatus").innerHTML == "Dev in Progress")
            {
                //Code here
            }
      }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM