如何使用JS或JQuery迭代获得gridview单元格值 [英] How to get gridview cell value iterating with JS or JQuery

查看:55
本文介绍了如何使用JS或JQuery迭代获得gridview单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过使用JQuery迭代GridView来获取单元格值.关键是我的gridview在内容占位符中,因此我无法使用#GridId来调用我的网格.我在JQuery中调用网格的方式是使用 $('[id $ = GridId']).我是JQuery的新手:p

I need to get cell values by iterating my GridView with JQuery. The thing is that my gridview in a content placeholder, so I can't call my grid by using #GridId. The way I call a grid in JQuery is using $('[id$=GridId']). I'm new in JQuery :p

推荐答案

假设您有一个像这样的GridView:

Let's say you have a GridView like this:

<form id="form1" runat="server">
    <asp:GridView ID="MyGridView" runat="server">
    </asp:GridView>
</form>

您可以通过使用 each 来迭代获取单元格的值,如下所示:

You can get values of cell with iterating by using each as following:

<script type="text/javascript">
        $(document).ready(function() {
              $("#<%=MyGridView.ClientID %> tr").each(function() {
                    var firstCellValue = $(this).find("td:eq(1)").html(); 
                    var lastCellValue = $(this).find("td:last").html();
                    //etc...
                });
        });
    </script>

请记住,如果您有表头,则应该跳过第一行:

Remember if you have table header then you should skip first row:

if (!this.rowIndex) return;

这篇关于如何使用JS或JQuery迭代获得gridview单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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