ASP.NET DataGrid and custom paging

后端 未结 1 2087
无人及你
无人及你 2020-12-19 23:37

I\'m trying to implement a DataGrid in ASP.NET, and want to achieve custom paging so that I don\'t have to provide all the data in one go. I\'ve spent several hours research

相关标签:
1条回答
  • 2020-12-19 23:57

    There is an error in your ASPX: to wire up the PageIndexChanged event handler use the property OnPageIndexChanged (not PageIndexChanged as in your code):

    <asp:DataGrid ID="myGrid" runat="server"
       OnPageIndexChanged="MyGrid_PageIndexChanged"  /// <--- here's the error
       ...
    

    Then, if you have AllowCustomPaging="true", you must ensure that the GetDataFromInternetSomehow() method will only return the data for the currently selected page, e.g. pass the current page to the method and return only the corresponding data:

    GetDataFromInternetSomehow(e.NewPageIndex);
    

    Otherwise, disable custom paging and it will just work (but all data will be loaded everytime).

    0 讨论(0)
提交回复
热议问题