日期:2014-05-17 浏览次数:20442 次
<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td> 班级编号:<%#Eval("classID ")%> </td> </tr> <tr> <td> <asp:Repeater ID="rpt2" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval("Name")%> </td> <td> <%#Eval("Age")%> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> public void Page_Load(object sender,EventArgs e) { if(!IsPostBack) { using(SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=NorthWind")) { string strSQL = "select classID from table1 group by classID"; //按组获取各个班级编号 SqlDataAdapter da= new SqlDataAdapter(strSQL,con); DataSet ds = new DataSet(); da.Fill(ds); this.rpt.DataSource = ds; this.rpt.DataBind(); } } } protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpt = (Repeater)e.Item.FindControl("rpt2"); //找到分类Repeater关联的数据项 DataRowView drv = (DataRowView)e.Item.DataItem; //提取班级ID int