web service filling gridview awfully slow, as is paging/sorting
- by nat
Hi
I am making a page which calls a web service to fill a gridview
this is returning alot of data, and is horribly slow.
i ran the svcutil.exe on the wsdl page and it generated me the class and config
so i have a load of strongly typed objects coming back from each request to the many service functions.
i am then using LINQ to loop around the objects grabbing the necessary information as i go, but for each row in the grid i need to loop around an object, and grab another list of objects (from the same request) and loop around each of them.. 1 to many parent object child one..
all of this then gets dropped into a custom datatable a row at a time.. hope that makes sense....
im not sure there is any way to speed up the initial load. but surely i should be able to page/sort alot faster than it is doing. as at the moment, it appears to be taking as long to page/sort as it is to load initially.
i thought if when i first loaded i put the datasource of the grid in the session, that i could whip it out of the session to deal with paging/sorting and the like.
basically it is doing the below
protected void Page_Load(object sender, EventArgs e)
{
//init the datatable
//grab the filter vars (if there are any)
WebServiceObj WS = WSClient.Method(args);
//fill the datatable (around and around we go)
foreach (ParentObject po in WS.ReturnedObj)
{
var COs = from ChildObject c in WS.AnotherReturnedObj
where c.whatever.equals(...) ...etc
foreach(ChildObject c in COs){
myDataTable.Rows.Add(tlo.this,
tlo.that,
c.thisthing,
c.thatthing,
etc......);
}
}
grdListing.DataSource = myDataTable;
Session["dt"] = myDataTable;
grdListing.DataBind();
}
protected void Listing_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdListing.PageIndex = e.NewPageIndex;
grdListing.DataSource = Session["dt"] as DataTable;
grdListing.DataBind();
}
protected void Listing_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = Session["dt"] as DataTable;
DataView dv = new DataView(dt);
string sortDirection = " ASC";
if (e.SortDirection == SortDirection.Descending)
sortDirection = " DESC";
dv.Sort = e.SortExpression + sortDirection;
grdListing.DataSource = dv.ToTable();
grdListing.DataBind();
}
am i doing this totally wrongly? or is the slowness just coming from the amount of data being bound in/return from the Web Service.. there are maybe 15 columns(ish) and a whole load of rows.. with more being added to the data the webservice is querying from all the time
any suggestions / tips happily received
thanks