Mvc Repeater
2009-07-04 01:35 蜡笔小旧 阅读(423) 评论(0) 编辑 收藏 举报(1)集成webform Repeater
public class MyReapter : System.Web.UI.WebControls.Repeater
{
public System.Web.Mvc.ViewPage ViewPage {
get { return base.Page as ViewPage; }
}
public System.String Key { get; set; }
protected override void OnLoad(EventArgs e)
{
this.DataSource = ViewPage.ViewData[Key];
this.DataBind();
base.OnLoad(e);
}
}
{
public System.Web.Mvc.ViewPage ViewPage {
get { return base.Page as ViewPage; }
}
public System.String Key { get; set; }
protected override void OnLoad(EventArgs e)
{
this.DataSource = ViewPage.ViewData[Key];
this.DataBind();
base.OnLoad(e);
}
}
(2)界面显示
<%@ Register Assembly="MvcApplication1" Namespace="MvcApplication1.Controllers" TagPrefix="Mvc" %>
<ul>
<mvc:MyReapter Key="User" runat="server">
<ItemTemplate>
<%# Eval("UserName")%>
</ItemTemplate>
</mvc:MyReapter>
</ul>
<mvc:MyReapter Key="User" runat="server">
<ItemTemplate>
<%# Eval("UserName")%>
</ItemTemplate>
</mvc:MyReapter>
</ul>
(3)代码优化,只注册一次。
<add assembly="MvcApplication1" namespace="MvcApplication1.Controllers" tagPrefix="Mvc"/>