用WebUserControl来展示产品列表

.aspx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProductBlockCtrl.ascx.cs" 
Inherits="企业网站.Ctrls.ProductBlockCtrl" %>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate><li><%#Eval("Name") %></li></ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

.aspx.cs

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                T_ProductsTableAdapter adapter = new T_ProductsTableAdapter();
                var data = adapter.GetDataByCatId(CatId);
                Repeater1.DataSource = data;
                Repeater1.DataBind();
            }
        }
        public long CatId //设置一个CatId以便于动态地根据产品类别获取数据源
        {
            get;
            set;
        }
    }


你可能感兴趣的:(object,C#,asp,产品)