Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to create a new webpage where i need to display almost 10 different gridviews and charts for each grid data.

Gridviews are binded on pageload event and charts are displayed using jquery-ajax method (using amcharts as well as highcharts) by calling WebMethod.

Initially i implemented the page in way that gridview binded after executing stored procedure and inside webmethod also executing the same sp for drawing chart.So same sp is executed twice for this page(one for grid and another for chart).so 10 sps needs to execute for grid and same 10 for charts.

So for improving the page performance i have created static datatable like this

C#
static DataTable Report1;


and binded the gridview like this.

C#
private void gvbindReport1()
    {
        try
        {
            Report1 = new DataTable();
            DataSet ReportDS1 = objmvbl.GetReportGraph(ClientID, date_From, date_To);
            if (ReportDS1.Tables.Count > 0)
            {
                Report1 = ReportDS1.Tables[0];

            }
            GdReport.DataSource = Report1;
            GdReport.DataBind();
        }
        catch (Exception ex)
        {
            Log.Errlog("Error Occured in  gvbindReport1 : " + ex.Message.ToString());
        }

    }


and inside the webmethod i have used the same datatable for drawing the chart like this


C#
[System.Web.Services.WebMethod]
    public static string GetDataReport1()
    {
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
        Dictionary<string, object> row;
        try
        {
            if (Report1.Rows.Count > 0)
            {
                foreach (DataRow dr in Report1.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in Report1.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
            }
        }
        catch (Exception ex)
        {
            Log.Errlog("Error Occured in  GetDataReport WebMethod of Report Page : " + ex.Message.ToString());
        }

        return serializer.Serialize(rows);

    }



with this i am able to show both grid and charts.

Now Please tell that, is this the correct approach to deal with webmethods? i have read that webmethod have no relation to the page and all. Tell me the draw backs of this method.

If this is wrong way,Please give some idea to improve the page performance?
Posted

1 solution

In Page Load event store the 10 sps datatable results in cache and use that while processing ajax requests, in this way single execution of sp and using result twice.
 
Share this answer
 
Comments
ATHUL AC 29-Sep-15 2:38am    
@aspdotnet sekhar: what ever i have implemented is wrong?
aspdotnet sekhar 29-Sep-15 2:47am    
No, not wrong but for same data you are calling db two times, not an optimised way , why waste server resources?
ATHUL AC 29-Sep-15 3:12am    
@aspdotnet sekhar: i am not calling db two times,in gvbindReport1 i am assigning values to static DataTable Report1 and later for web method i am using the same datatable..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900