repeater 嵌套
代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable
Dim sqlCom As SQLCommon = New SQLCommon
dt = sqlCom.ExecuteQuery("SELECT * FROM tblProductCategory")
Me.rptCategory.DataSource = dt
Me.rptCategory.DataBind()
End Sub
Protected Sub rptCategory_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategory.ItemDataBound
Dim sqlCom As SQLCommon = New SQLCommon
Dim dt As DataTable = New DataTable
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rep As System.Web.UI.WebControls.Repeater = e.Item.FindControl("rptSubCategory")
Dim rowv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim strKey As String = CType(rowv("productCategoryName"), String)
dt = sqlCom.ExecuteQuery("SELECT * FROM tblProductSubCategory WHERE productCategoryName='" & strKey & "'")
rep.DataSource = dt
rep.DataBind()
End If
End Sub
Dim dt As DataTable = New DataTable
Dim sqlCom As SQLCommon = New SQLCommon
dt = sqlCom.ExecuteQuery("SELECT * FROM tblProductCategory")
Me.rptCategory.DataSource = dt
Me.rptCategory.DataBind()
End Sub
Protected Sub rptCategory_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategory.ItemDataBound
Dim sqlCom As SQLCommon = New SQLCommon
Dim dt As DataTable = New DataTable
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rep As System.Web.UI.WebControls.Repeater = e.Item.FindControl("rptSubCategory")
Dim rowv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim strKey As String = CType(rowv("productCategoryName"), String)
dt = sqlCom.ExecuteQuery("SELECT * FROM tblProductSubCategory WHERE productCategoryName='" & strKey & "'")
rep.DataSource = dt
rep.DataBind()
End If
End Sub
代码
<form id="form1" runat="server">
<asp:Repeater ID="rptCategory" runat="server">
<ItemTemplate>
<%#Eval("productCategoryName")%> <br />
<asp:Repeater ID="rptSubCategory" runat ="server" >
<ItemTemplate >
<div style ="color :Red;"><%#Eval("productSubCategoryName")%> </div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</form>
<asp:Repeater ID="rptCategory" runat="server">
<ItemTemplate>
<%#Eval("productCategoryName")%> <br />
<asp:Repeater ID="rptSubCategory" runat ="server" >
<ItemTemplate >
<div style ="color :Red;"><%#Eval("productSubCategoryName")%> </div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</form>