怎么在Repeater中嵌套Repeater-创新互联
本篇文章为大家展示了怎么在Repeater中嵌套Repeater,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
我们提供的服务有:成都网站建设、做网站、微信公众号开发、网站优化、网站认证、太谷ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的太谷网站制作公司protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.dtCategory = GetCategoryTable(); this.dtProduct = GetProductTable(); rptCategoryList.DataSource = dtCategory; rptCategoryList.DataBind(); } } // 准备一张分类表 DataTable GetCategoryTable() { DataTable dt = new DataTable(); dt.Columns.Add("CategoryId", typeof(int)); dt.Columns.Add("CategoryTitle", typeof(string)); for (int i = 1; i <= 3; i++) { DataRow row = dt.NewRow(); row["CategoryId"] = i; row["CategoryTitle"] = "分类名字 " + i + ""; dt.Rows.Add(row); } return dt; } // 准备一张产品表 DataTable GetProductTable() { DataTable dt = new DataTable(); dt.Columns.Add("ProductTitle", typeof(string)); dt.Columns.Add("CategoryId", typeof(int)); for (int i = 1; i <= 9; i++) { DataRow row = dt.NewRow(); row["ProductTitle"] = "产品名字 " + i + ""; if (i > 6) row["CategoryId"] = 3; else if (i > 3) row["CategoryId"] = 2; else row["CategoryId"] = 1; dt.Rows.Add(row); } return dt; } // 获取某个类别的产品 DataTable GetProductTable(int categoryId) { DataView dv = this.dtProduct.DefaultView; dv.RowFilter = " CategoryId=" + categoryId + " "; return dv.ToTable(); } protected void rptCategoryList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { DataRowView drv = (DataRowView)e.Item.DataItem; Literal ltlTitle = (Literal)e.Item.FindControl("ltlTitle"); ltlTitle.Text = drv["CategoryTitle"].ToString(); Repeater rptProductList = (Repeater)e.Item.FindControl("rptProductList"); rptProductList.DataSource = GetProductTable(Convert.ToInt32(drv["CategoryId"])); rptProductList.DataBind(); } } protected void rptProductList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { DataRowView drv = (DataRowView)e.Item.DataItem; Literal ltlTitle = (Literal)e.Item.FindControl("ltlTitle"); ltlTitle.Text = drv["ProductTitle"].ToString(); } }
前台aspx代码
<form id="form1" runat="server"> <div> <asp:Repeater ID="rptCategoryList" runat="server" OnItemDataBound="rptCategoryList_ItemDataBound"> <ItemTemplate> <div class="listBox"> <div class="title"> <asp:Literal ID="ltlTitle" runat="server">asp:Literal>div> <div class="content"> <ul> <asp:Repeater ID="rptProductList" runat="server" OnItemDataBound="rptProductList_ItemDataBound"> <ItemTemplate> <li> <asp:Literal ID="ltlTitle" runat="server">asp:Literal> li> ItemTemplate> asp:Repeater> ul> div> div> ItemTemplate> asp:Repeatdiv> form>
上述内容就是怎么在Repeater中嵌套Repeater,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
网页题目:怎么在Repeater中嵌套Repeater-创新互联
转载源于:http://azwzsj.com/article/disgpe.html