Can we use same datatable for pagemethod and webmethod in ASP.NET?

后端 未结 4 1456
广开言路
广开言路 2021-02-20 16:02

I am trying to create a new webpage where i need to display almost 10 different gridviews and charts.

Gridviews are binded on pageload event and charts are displayed usi

4条回答
  •  醉酒成梦
    2021-02-20 16:36

    Looking at the code sample that you have given (and the parameters date_from and date_to that you are passing to GetReportGraph()) I assume:

    1. you have 2 input fields where user is specifying the date range and then submitting the data (causing postback), based on which you are filtering the records and showing in grid as well as chart.

    2. as different users would be providing different date ranges, you don't want to show the same data to all users.

    3. as the data is filtered, its not going to have thousands of records.

    I'm not sure what functionality of grid view you are using. Is it used only to show read only tabular data? If yes, you can consider the approach given by @Nabin Karki Thapa. If not check the alternate approach below:

    After you have got the data table and bound it to grid view, immediately serialize it to JSON and register it as a script block (define a JS variable and assign the serialized JSON as it's value).

    On the client side, while charting, instead of invoking webmethod, to get the JSON object use the JS variable that you have registered. This way you will avoid the call to web method (AJAX) and extra stored procedure call altogether.

提交回复
热议问题