我有一个webapp,可以创建一些webgets并在Gridview
中返回结果。有时,应用程序可能需要制作400多个网站,但只能在网格中填充15-20个记录。
是否可以部分加载GridView
,以便将每条记录附加到现有GridView
?
添加代码
List<Test> testList = new List<Test>();
foreach (Location str in list)
{
string url;
try
{
url = "http://www.test.com/" + str.Url;
XmlReader reader = XmlReader.Create(url);
Rss10FeedFormatter formatter = new Rss10FeedFormatter();
if (formatter.CanRead(reader))
{
formatter.ReadFrom(reader);
IEnumerable<SyndicationItem> items = formatter.Feed.Items;
int itemCt = 1;
foreach (SyndicationItem item in items)
{
Test test = new Test();
test.Name = item.Name;
test.City= item.City;
testList.Add(data);
//if I add this here, the RowDatabound does not fire, if I take out, it works fine but only after all requests are made
listGrid.DataSource = temp;
listGrid.DataBind();
}
}
else
throw new ApplicationException("Invalid RSS 1.0 feed at " + FeedUrl.Text.Trim());
}
答案 0 :(得分:1)
创建一个单独的列表,您将DataBind到Gridview,然后每当您更改该列表中的元素时,只需重新绑定gridview。
var mySmallerList = bigList.Skip(someNumber).Take(someOtherNumber);
myGridView.DataSource = mySmallerList;