標籤:style blog io color ar sp 資料 div on
<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 5px" width="100%"> <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound"> <ItemTemplate> <tr> <td class="fb"> <a href="Lists.aspx?Qtid=<%#Eval("qtid") %>"><%#Eval("qtypename") %></a> <span id="askCount_15" class="date2">[<%#Eval("typecount")%>]</span> </td> </tr> <tr> <td> <div id="askTop2_15" class="ask_list"> <asp:Repeater runat="server" ID="rpquestionlist"> <ItemTemplate> <a href="Question.aspx?qid=<%#Eval("liftquestionid")%>"> <%#Eval("questiontitle")%></a><br /> 父級資料:<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "qtid")%> 父級序號:<%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %> </ItemTemplate> </asp:Repeater> </div> </td> </tr> </ItemTemplate> </asp:Repeater></table>
private void Repeater1Bind() {//GetQuestionTypeAndCount() 返回一個datatable this.rptypelist.DataSource = LiftQuestionCtr.GetQuestionTypeAndCount(); this.rptypelist.DataBind(); } protected void rptypelist_ItemDataBound(object sender, RepeaterItemEventArgs e) {//判斷裡層repeater處於外層repeater的哪個位置( AlternatingItemTemplate,FooterTemplate,//HeaderTemplate,,ItemTemplate,SeparatorTemplate) if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("rpquestionlist") as Repeater;//找到裡層的repeater對象 DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分類Repeater關聯的資料項目 int typeid = Convert.ToInt32(rowv["qtid"]); //擷取填充子類的id rep.DataSource = LiftQuestionCtr.GetSomeQuestionsByTypeid(typeid, 2); rep.DataBind(); } }
轉:Repeater嵌套綁定Repeater以及內層調用外層資料