2012-06-29 34 views
0

我似乎無法讓我的數據插件正常工作。我一直在尋找答案,看來我得到的錯誤「ListView與ID'searchResults'必須有一個數據源,實現ICollection或可以執行數據源分頁,如果AllowPaging爲真。」是很常見的,通常的答案是將ToArray()放在DataSource上。不過,我不知道如何把數組放在我的鏈接聲明。有人可以請指教。DataPager無法使用我的數據源

 searchResults.DataSource = from r in response.Results 
     select new 
     { 
      Title = r[SearchContentProperty.Title], 
      Summary = r[SearchContentProperty.HighlightedSummary] 
     }; 

    searchResults.DataBind(); 

回答

2

和toArray()添加到您的LINQ查詢試試這個:

searchResults.DataSource = (from r in response.Results 
    select new 
    { 
     Title = r[SearchContentProperty.Title], 
     Summary = r[SearchContentProperty.HighlightedSummary] 
    }).ToArray(); 

searchResults.DataBind(); 
1
searchResults.DataSource = (from r in response.Results 
select new 
{ 
    Title = r[SearchContentProperty.Title], 
    Summary = r[SearchContentProperty.HighlightedSummary] 
}).ToArray(); 

searchResults.DataBind(); 是真實的,

編輯:我得到了大致相同的問題,但如果依然傳呼不wotking可以使用SearchResult所PagePropertiesChanging事件和寫代碼像這樣得到尋呼精細

protected void searchResults_PagePropertiesChanging(object sender,PagePropertiesChangingEventArgs e) 
{ 
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); 

//write your codes again to bind data,for this example: 


searchResults.DataSource = from r in response.Results 
select new 
{ 
    Title = r[SearchContentProperty.Title], 
    Summary = r[SearchContentProperty.HighlightedSummary] 
}; 

searchResults.DataBind(); 
} 
相關問題