【问题标题】:How to loop through each row of gridview in jquery?如何循环遍历jquery中的每一行gridview?
【发布时间】:2016-12-27 08:26:21
【问题描述】:

您好,我正在 asp.net 中开发一个应用程序。我有一个带有隐藏字段的网格视图。我想遍历隐藏字段的每一行,我想获得隐藏字段的值。这是我的网格视图。

<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkRow" runat="server" />
                <asp:HiddenField ID="Hidden" runat="server" Value='<%#Eval("Name")%>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
        <asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
            <ItemTemplate>
                <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

我希望 javascript 遍历 gridview 的每一行。

$('#<%= GridView1.ClientID %> input[type="HiddenField"]').each(function () {
              //Get hidden field value
            });

我可以得到一些帮助如何获取隐藏字段值。谢谢大家

【问题讨论】:

  • 你的意思是把$(this).val();在循环中?
  • 感谢您的回复。是的。我想获得隐藏的字段值。我可以知道这是否可行吗?警报($(this).val());

标签: javascript jquery asp.net gridview


【解决方案1】:

试试:

var ResultArray =[];
$('#<%=GridView1.ClientID %>').find('input:hidden').each(function() {
    ResultArray.push($(this).val());
});

alert(ResultArray) // you get all hidden field value in array .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 2016-07-20
    • 2019-06-12
    • 2014-06-29
    • 1970-01-01
    • 2015-04-14
    • 2021-03-11
    相关资源
    最近更新 更多