'Visit http://www.laptrinhdotnet.com for more ASP.NET Tutorials
Namespace NestedRepeater
Public Class _Default
Inherits System.Web.UI.Page
#Region "Bind Data"
Private SubBindCategories()
Dim objBind As New DataTable
objBind = BindData()
If Not objBind Is Nothing Then
If objBind.Rows.Count > 0 Then
rptCategory.DataSource = objBind
rptCategory.DataBind()
rptCategory.Visible = True
updatePanel.Update()
Else
rptCategory.Visible = False
EndIf
End If
End Sub
Private FunctionBindData() As DataTable
Dim objSQL As New SqlDataProvider
Dim objBind As DataTable = objSQL.FillTable("Select Categories.* From Categories")
Return objBind
End Function
Private FunctionBindProduct(ByVal CategoryID As Integer) As DataTable
Dim objSQL As New SqlDataProvider
Dim objBind As DataTable = objSQL.FillTable("Select top 5 Products.* From Products Where CategoryID=" & CategoryID & "")
Return objBind
End Function
#End Region
#Region "Datalist Methods"
Private SubrptCategory_ItemDataBound(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategory.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim CategoryID AsInteger = DataBinder.Eval(e.Item.DataItem, "CategoryID")
Dim objBind AsNew DataTable
objBind = BindProduct(CategoryID)
If objBind.Rows.Count <> 0 Then
Dim lstDetail AsRepeater = DirectCast(e.Item.FindControl("rptProduct"), Repeater)
If NotlstDetail Is NothingThen
lstDetail.DataSource = objBind
lstDetail.DataBind()
End If
End If
End If
End Sub
Public SubDetail_Command(ByVal source As Object, ByVal e AsSystem.Web.UI.WebControls.RepeaterCommandEventArgs)
If (e.CommandName.ToLower <> "sort" Ande.CommandName.ToLower <> "page") Then
Dim CommandArgument() As String = e.CommandArgument.ToString.Split(",")
Dim ItemID AsInteger = -1
Dim ItemName AsString = ""
Dim UnitPrice AsString = ""
If CommandArgument.Length > 0 Then
ItemID = CommandArgument(0)
ItemName = CommandArgument(1)
UnitPrice = CommandArgument(2)
End If
Select Casee.CommandName.ToLower
Case "detail"
Dim sMessage As String = "Product Name: " & ItemName.ToString() & "\n"& "Price:" & UnitPrice
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), "alert", "alert('"& sMessage & "');", True)
End Select
End If
End Sub
Public SubDetail_Bound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
Try
If (e.Item.ItemType = ListItemType.Item Ore.Item.ItemType = ListItemType.AlternatingItem) Then
Dim ProductID AsInteger = DataBinder.Eval(e.Item.DataItem, "ProductID")
Dim lnkProductImage As HyperLink = DirectCast(e.Item.FindControl("lnkProductImage"), HyperLink)
If Not lnkProductImage IsNothing Then
Dim imgArticleImage As Image = DirectCast(lnkProductImage.FindControl("imgProductImage"), Image)
If Not imgArticleImage Is Nothing Then
imgArticleImage.ImageUrl = Page.ResolveUrl("Images/no_image.jpg")
imgArticleImage.ImageAlign = ImageAlign.AbsMiddle
End If
End If
End If
Catch exception As Exception
End Try
End Sub
#End Region
#Region "Event Handles"
Protected SubPage_Load(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Me.Load
Try
If Page.IsPostBack = False Then
BindCategories()
End If
Catch ex As Exception
End Try
End Sub
#End Region
End Class
End Namespace