将 LinqToSql 表绑定到 Repeater
我有一个从数据库检索数据的类。
[Table(Name = "Ilanlar")]
public class Ilan
{
[Column(Name="ilan_id" ,IsPrimaryKey = true)]
public int M_ilan_id;
[Column(Name="refVerenUser_id")]
public int M_refVerenUser_id;
}
我通过上面的类绑定来自数据库的数据。
private void ItemsGet()
{
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = f_IlanlariGetir(CurrentPage);
objPds.AllowPaging = true;
objPds.PageSize = 3;
objPds.CurrentPageIndex = CurrentPage;
rptIlanlar.DataSource = objPds; //rptIlanlar = asp:Repeater
rptIlanlar.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
ItemsGet();
}
private System.Collections.IEnumerable f_IlanlariGetir(int p)
{
Context context = new Context(DAO.dbYaban.ConnectionString);
return context.GetTable<Ilan>();
}
但结果是 IEnumerable 但我需要类似 DataSet 的东西。 我收到此错误:
我找到了关于此错误的很好的解释,它是:
底层数据源必须支持 ICollection 接口 命令网格执行自动分页。 ICollection 需要一个 类来实现 Count 属性。 ArrayList 和 DataView 两者 支持该接口,因此您可以将它们用作数据源。其他类仅支持 IEnumerable 接口。这让他们 用作数据源,但不用作分页数据源。 SqlDataReader 就是此类的一个示例。 参考
但我需要将转发器与 linq to sql 表的结果绑定。我应该怎么办?
I have a class which retrieves the data from DB.
[Table(Name = "Ilanlar")]
public class Ilan
{
[Column(Name="ilan_id" ,IsPrimaryKey = true)]
public int M_ilan_id;
[Column(Name="refVerenUser_id")]
public int M_refVerenUser_id;
}
And i am binding the data comes from db via the class above.
private void ItemsGet()
{
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = f_IlanlariGetir(CurrentPage);
objPds.AllowPaging = true;
objPds.PageSize = 3;
objPds.CurrentPageIndex = CurrentPage;
rptIlanlar.DataSource = objPds; //rptIlanlar = asp:Repeater
rptIlanlar.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
ItemsGet();
}
private System.Collections.IEnumerable f_IlanlariGetir(int p)
{
Context context = new Context(DAO.dbYaban.ConnectionString);
return context.GetTable<Ilan>();
}
But the result is IEnumerable but i need something like DataSet.
I'm getting this error:
I found good explanation about this error, it is:
The underlying DataSource has to support the ICollection interface in
order for the grid to perform automatic paging. ICollection requires a
class to implement a Count property. ArrayList and DataView both
support the interface, so you could use them as DataSources.Other classes only support the IEnumerable interface. This allows them
to be used as a DataSource but not as a paged data source.
SqlDataReader would be an example of such a class. Reference
But i need to bind repeater with the results of linq to sql tables. What should i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要直接绑定到查询,而是尝试:
Rather than binding directly to the query, try: