<asp:Repeater ID="RepSort1" runat="server" OnItemDataBound="RepSort1_ItemDataBound"> <ItemTemplate> <table> <tr> <th> <a href='Show.aspx?sortid=<%#Eval("ID") %>'><%#Eval("TypeName") %></a> </th> </tr> <tr> <td ><%#Eval("ID") %></td> </tr> <asp:Repeater ID="RepSort2" runat="server" OnItemDataBound="RepSort2_ItemDataBound"> <ItemTemplate> <tr> <td class="mc"><%#Eval("TypeName") %></td> <td> <asp:Repeater ID="RepSort3" runat="server"> <ItemTemplate> <a href='#'><%#Eval("TypeName")%></a> </ItemTemplate> </asp:Repeater> </td> </tr> </ItemTemplate> </asp:Repeater> </table> </ItemTemplate> </asp:Repeater>
后台代码:
protected void RepSort1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("RepSort2") as Repeater; DataRowView rowv = (DataRowView)e.Item.DataItem; string pid=rowv["id"].ToString(); rep.DataSource = GetItem(pid.ToString()); rep.DataBind(); } } protected void RepSort2_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("RepSort3") as Repeater; DataRowView rowv = (DataRowView)e.Item.DataItem; string pid = rowv["id"].ToString(); rep.DataSource = GetItem(pid.ToString()); rep.DataBind(); } } public DataSet GetItem(string pid) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString); SqlCommand com = new SqlCommand("select * from [P-Type] where pid="+pid, con); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); return ds; }