How to count the rows in a gridview in asp.net using jQuery

前端 未结 4 1551
逝去的感伤
逝去的感伤 2021-01-13 04:54

Does anyone know how to count the no of rows in asp:GridView using jQuery. If no rows found then I want to do stuff...

4条回答
  •  盖世英雄少女心
    2021-01-13 05:30

    Every GridView produces HTML that is basically a table and that table has an ID (view source of your output page to know what im talking about). You can pass the ID either from .Net to JavaScript by means of myGridView.ClientID or in ASP.NET 4 make the ClientIdMode="Static" and thus use the exact same ID you use for the ASP control.

    Then in jquery (which is a client-side layer that is completely seperated from the GridView layer), grab that ID and count:

    $("#mygridviewid tr").length;
    

提交回复
热议问题