【问题标题】:how can I apply Datatable jquery on asp.net GridView?如何在 asp.net GridView 上应用 Datatable jquery?
【发布时间】:2016-04-19 09:05:41
【问题描述】:
 <asp:GridView ID="grdDonationRequests" runat="server" SelectMethod="grdDonationRequests_GetData" AutoGenerateColumns="False"
                                 AllowPaging="True"  PagerSettings-Mode="NumericFirstLast"  PageSize="10" DataKeyNames="DonationRequestID" ItemType="Tayf.Models.DonationRequest"
                                AllowSorting="true" Width="100%" CssClass=" table-striped table-condensed table table-bordered table-hover" meta:resourcekey="grdDonationRequestsResource1">

我尝试过这样做

    $(function () {            
         $("#<%=grdDonationRequests.ClientID%>").prepend(
$("thead>/thead>").append($(this).find("tr:first"))).dataTable({             
                    });
                });

但它给了我一个错误 Uncaught TypeError: Cannot read property 'className' of undefined

Update:-

当我尝试这个 '$("#&lt;%=grdDonationRequests.ClientID%&gt;").dataTable({ "aaSorting": [] });' 时,它没有给我任何错误,也将 gridview 绘制为数据表,但将其显示为空

【问题讨论】:

  • 不清楚你在问什么。能详细解释一下吗?
  • @PiyushKhatri 我需要在我的 asp.net gridview 上应用 datatable jquery 插件,这使我能够搜索、排序、分页等。

标签: javascript jquery asp.net gridview datatables


【解决方案1】:

我现在正在做这件事。以下代码就是将 gridview 实际转换为数据表所需的全部内容:

$(document).ready(function () {
var table = $('#your_gridview_id').DataTable();

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    试试这个

    $(function () {            
      $("#<%=grdDonationRequests.ClientID%>").dataTable({ 
      });
    });
    

    也看this的回答

    【讨论】:

    • 当我尝试这个'$("#&lt;%=grdDonationRequests.ClientID%&gt;").GridviewFix().dataTable({ "aaSorting": [] });' 时,它没有给我任何错误,也将gridview 绘制为数据表,但将其显示为空
    猜你喜欢
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2019-01-15
    • 1970-01-01
    相关资源
    最近更新 更多