我正在調用一個Web服務來填充GridView的頁面 這是返回大量的數據,並且非常慢。Web服務填充GridView非常緩慢,因爲是分頁/排序
我在wsdl頁面上運行了svcutil.exe,它生成了我的類和配置 ,所以我有從每個請求返回到許多服務功能的強類型對象的負載。我接着使用LINQ來循環抓取所需信息的對象,但是對於網格中的每一行,我需要循環一個對象,並抓取另一個對象列表(來自同一個請求)和循環他們中的每一個.. 1到許多父對象>兒童之一.. 然後所有這些然後被放入到一個自定義的數據表中一行一次..希望是有道理的....
即時通訊不確定有什麼辦法可以加快初始負載。 但我當然應該能夠更快地進行頁面排序/排序比編寫更快。就目前而言,它似乎需要花費很長時間來進行頁面/排序,因爲它最初是要加載的。
我想如果我第一次加載,我把網格的數據源放在會話中,我可以將它從會話中甩出來處理分頁/排序等。
主要是做以下
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();
}
我完全錯誤地這樣做呢?或者是來自Web服務中綁定/返回的數據量的緩慢。有可能是15列(ish)和整行負載...更多的數據被添加到Web服務正在查詢的數據中
任何建議/提示興高采烈地
感謝
所有的時間