Repeater嵌套经常要用到,总结一下。
<asp:Repeater ID="repSingle" runat="server" onitemcommand="repSingle_ItemCommand" onitemdatabound="repSingle_ItemDataBound"> <ItemTemplate> <li>序号<asp:TextBox ID="texTrueFalseSequence" runat="server" Width="20px" Text='<%#Eval("Sequence")%>'></asp:TextBox> <%#Eval("QuestionTitle")%></li> <!--begin选项--> <li> <ul> <asp:Repeater ID="repSingleChoices" runat="server"> <ItemTemplate> <li><%# Container.ItemIndex + 1%>,<%#Eval("ItemContent")%></li> </ItemTemplate> </asp:Repeater> </ul> </li> <!--end选项--> </ItemTemplate> </asp:Repeater>
protected void repSingle_ItemDataBound(object sender, RepeaterItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater singleChoice = e.Item.FindControl("repSingleChoices") as Repeater; Question row = (Question)e.Item.DataItem; //int curSequence = Convert.ToInt32(row["Sequence"].ToString()); //Question curQuestion = questionnaire.Questions.Find(a => (a.QuestionType == QuestionType.singlechoice && a.Sequence == curSequence)); singleChoice.DataSource = row.ChoiceItems; singleChoice.DataBind(); } }
发现一个现象,即使没有设置AlternatingItem,默认仍然会在第一行是ListItemType.Item,第二行是ListItemType.AlternatingItem,如此交替下去
作者:Tyler Ning
出处:http://www.cnblogs.com/tylerdonet/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过以下邮箱地址williamningdong@gmail.com 联系我,非常感谢。