显示从数据集到asp.net转发器控件的5行

时间:2014-03-19 07:33:24

标签: c# asp.net visual-studio-2010

我在会话对象中有数据集,包含所有用户记录  在某个地方,我必须显示所有(200行)记录,其中只有5个在asp.net转发器控件

我试图显示5条记录/行,但现在仍在显示200条记录

DataSet tempDS = (DataSet)Application["ActivityDS"];

//I tried both but now working
tempDS.Tables[0].Rows.Cast<System.Data.DataRow>().Take(5);
OR 
tempDS.Tables[0].AsEnumerable().Take(5);

repSearchResult.DataSource = tempDS;
repSearchResult.DataBind();

我需要做什么来显示从数据集到asp.net转发器控件的5行

1 个答案:

答案 0 :(得分:1)

尝试:

var datasource=tempDS.Tables[0].AsEnumerable().Take(5);
repSearchResult.DataSource = datasource;
repSearchResult.DataBind();

您还可以查看:http://msdn.microsoft.com/en-us/library/bb503062(v=vs.110).aspx

  

返回值类型: System.Collections.Generic.IEnumerable<TSource>

     

这是   IEnumerable<T>包含指定数量的元素   输入序列的开始。

因此,使用此方法您不会修改原始序列,而是创建并返回新的IEnumerable