泛型实体类List<>绑定到repeater

时间:2023-02-04 23:35:04

后台代码:

private void bindnewslist()
{
long num = 100L;
List<Model.news> news = _news.GetList(out num);
this.newslist.DataSource = news;
this.newslist.DataBind();
}

说明:Model.news是实体类,GetList(out long)方法返回List<Model.news>.

前台代码:

<ul class="dot">
<asp:Repeater ID="newslist" runat="server" >
<ItemTemplate>
<li><a href="#"><%# (Container.DataItem as Model.news).title %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>

说明:title为实体类Model.news的一个属性。

另绑定List<string>时直接用Container.DataItem 即可。