Dear Sir,
I am unable to access controls inside a radmenu dynamic template. I am want to handle radlistbox selectedindexchanged event or access selectedvalue property when the menu item is clicked. Please help
Private Sub mnuRoom_ItemClick(sender As Object, e As Telerik.Web.UI.RadMenuEventArgs) Handles mnuRoom.ItemClick
If e.Item.Level = 0 Then
Response.Redirect("~/Pages/Products.aspx?category=" & e.Item.Value)
Else
Dim lstCat As RadListBox = DirectCast(e.Item.FindControl("lstCategories"), RadListBox)
Response.Redirect("~/Pages/Products.aspx?category=" & lstCat.SelectedValue)
End If
End Sub
Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
Using dbContext As New familia.OpenAccess.EntitiesModel
mnuRoom.Items.Clear()
Dim room As IQueryable(Of ProductCategory)
room = From r In dbContext.ProductCategories Where r.IsActive = True And r.ParentCategory = 0 Select r
For Each r In room
Dim roomitem As New Telerik.Web.UI.RadMenuItem
roomitem.DataItem = r
roomitem.Value = r.CategoryID
mnuRoom.Items.Add(roomitem)
Dim mainmenuItemTemplate As New MainMenuItemTemplate()
mainmenuItemTemplate.InstantiateIn(roomitem)
Dim childItem As New RadMenuItem()
childItem.CssClass = "mainmenudropdown"
childItem.ItemTemplate = New MenuItemTemplate()
roomitem.Items.Add(childItem)
Next
End Using
End Sub
Class MenuItemTemplate
Implements ITemplate
#Region "ITemplate Members"
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim parentItem As RadMenuItem = DirectCast(container.Parent, RadMenuItem)
Dim room As ProductCategory = DirectCast(parentItem.DataItem, ProductCategory)
'Dim div As New HtmlGenericControl("div")
Dim contents As New Panel
contents.CssClass = "menucontents"
container.Controls.Add(contents)
Dim categories As New Panel
categories.CssClass = "menucategorypanel"
Dim l As New Label
l.ForeColor = System.Drawing.ColorTranslator.FromHtml("#1B75BC")
l.Font.Size = 14
l.Font.Bold = True
l.Text = room.CategoryName
categories.Controls.Add(l)
Dim cat As New RadListBox
cat.CssClass = "menucategorylist"
Using dbContext As New familia.OpenAccess.EntitiesModel
room.RoomID))
cat.DataSource = From c In dbContext.ProductCategories Where c.IsActive = True And c.ParentCategory = room.CategoryID Select c
cat.DataTextField = "CategoryName"
cat.DataValueField = "CategoryID"
cat.ID = "lstCategories"
cat.Width = 231
cat.DataBind()
End Using
AddHandler cat.SelectedIndexChanged, New EventHandler(AddressOf lstCategories_SelectedIndexChanged)
cat.Font.Size = 12
categories.Controls.Add(cat)
contents.Controls.Add(categories)
Dim brands As New Panel
brands.CssClass = "menubrandpanel"
Dim b As New Label
b.ForeColor = System.Drawing.ColorTranslator.FromHtml("#6B6B6B")
b.Font.Size = 14
b.Font.Bold = True
b.Text = "TOP BRANDS"
brands.Controls.Add(b)
Dim bnd As New RadListBox
bnd.CssClass = "menucategorylist"
Using dbContext As New familia.OpenAccess.EntitiesModel
bnd.DataSource = dbContext.ProductBrands.Where(Function(c) c.TopBrand = True And c.ProductCategories.Any(Function(r) r.CategoryID = room.CategoryID))
bnd.DataTextField = "BrandName"
bnd.DataValueField = "BrandID"
bnd.Width = 231
bnd.DataBind()
End Using
bnd.Font.Size = 12
brands.Controls.Add(bnd)
contents.Controls.Add(brands)
Dim bottom As New Panel
bottom.CssClass = "menucategorybottom"
Dim bimg As New RadBinaryImage
bimg.ImageUrl = "/images/layout/brand.png"
bimg.ResizeMode = BinaryImageResizeMode.Fit
bimg.Width = 20
bimg.Height = 20
bimg.CssClass = "buttonimage"
bottom.Controls.Add(bimg)
Dim brand As New RadButton
brand.ButtonType = RadButtonType.LinkButton
brand.CssClass = "brandbutton"
brand.Font.Bold = True
brand.Font.Size = 10
brand.Text = "All Brands"
bottom.Controls.Add(brand)
Dim bdimg As New RadBinaryImage
bdimg.ImageUrl = "/images/layout/BestDeals.png"
bdimg.ResizeMode = BinaryImageResizeMode.Fit
bdimg.Width = 20
bdimg.Height = 20
bdimg.CssClass = "buttonimage"
bottom.Controls.Add(bdimg)
Dim deals As New RadButton
deals.ButtonType = RadButtonType.LinkButton
deals.CssClass = "brandbutton"
deals.Font.Bold = True
deals.Font.Size = 10
deals.Text = "Best Deals"
bottom.Controls.Add(deals)
Dim psimg As New RadBinaryImage
psimg.ImageUrl = "/images/layout/Premimum.png"
psimg.ResizeMode = BinaryImageResizeMode.Fit
psimg.Width = 20
psimg.Height = 20
psimg.CssClass = "buttonimage"
bottom.Controls.Add(psimg)
Dim pre As New RadButton
pre.ButtonType = RadButtonType.LinkButton
pre.CssClass = "brandbutton"
pre.Font.Bold = True
pre.Font.Size = 10
pre.Text = "Premium Selections"
bottom.Controls.Add(pre)
Dim nimg As New RadBinaryImage
nimg.ImageUrl = "/images/layout/new.png"
nimg.ResizeMode = BinaryImageResizeMode.Fit
nimg.Width = 20
nimg.Height = 20
nimg.CssClass = "buttonimage"
bottom.Controls.Add(nimg)
Dim ne As New RadButton
ne.ButtonType = RadButtonType.LinkButton
ne.CssClass = "brandbutton"
ne.Font.Bold = True
ne.Font.Size = 10
ne.Text = "Recently Added"
bottom.Controls.Add(ne)
contents.Controls.Add(bottom)
End Sub
Private Sub lstCategories_SelectedIndexChanged(sender As Object, e As System.EventArgs)
End Sub
#End Region
End Class
I am unable to access controls inside a radmenu dynamic template. I am want to handle radlistbox selectedindexchanged event or access selectedvalue property when the menu item is clicked. Please help
Private Sub mnuRoom_ItemClick(sender As Object, e As Telerik.Web.UI.RadMenuEventArgs) Handles mnuRoom.ItemClick
If e.Item.Level = 0 Then
Response.Redirect("~/Pages/Products.aspx?category=" & e.Item.Value)
Else
Dim lstCat As RadListBox = DirectCast(e.Item.FindControl("lstCategories"), RadListBox)
Response.Redirect("~/Pages/Products.aspx?category=" & lstCat.SelectedValue)
End If
End Sub
Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
Using dbContext As New familia.OpenAccess.EntitiesModel
mnuRoom.Items.Clear()
Dim room As IQueryable(Of ProductCategory)
room = From r In dbContext.ProductCategories Where r.IsActive = True And r.ParentCategory = 0 Select r
For Each r In room
Dim roomitem As New Telerik.Web.UI.RadMenuItem
roomitem.DataItem = r
roomitem.Value = r.CategoryID
mnuRoom.Items.Add(roomitem)
Dim mainmenuItemTemplate As New MainMenuItemTemplate()
mainmenuItemTemplate.InstantiateIn(roomitem)
Dim childItem As New RadMenuItem()
childItem.CssClass = "mainmenudropdown"
childItem.ItemTemplate = New MenuItemTemplate()
roomitem.Items.Add(childItem)
Next
End Using
End Sub
Class MenuItemTemplate
Implements ITemplate
#Region "ITemplate Members"
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim parentItem As RadMenuItem = DirectCast(container.Parent, RadMenuItem)
Dim room As ProductCategory = DirectCast(parentItem.DataItem, ProductCategory)
'Dim div As New HtmlGenericControl("div")
Dim contents As New Panel
contents.CssClass = "menucontents"
container.Controls.Add(contents)
Dim categories As New Panel
categories.CssClass = "menucategorypanel"
Dim l As New Label
l.ForeColor = System.Drawing.ColorTranslator.FromHtml("#1B75BC")
l.Font.Size = 14
l.Font.Bold = True
l.Text = room.CategoryName
categories.Controls.Add(l)
Dim cat As New RadListBox
cat.CssClass = "menucategorylist"
Using dbContext As New familia.OpenAccess.EntitiesModel
room.RoomID))
cat.DataSource = From c In dbContext.ProductCategories Where c.IsActive = True And c.ParentCategory = room.CategoryID Select c
cat.DataTextField = "CategoryName"
cat.DataValueField = "CategoryID"
cat.ID = "lstCategories"
cat.Width = 231
cat.DataBind()
End Using
AddHandler cat.SelectedIndexChanged, New EventHandler(AddressOf lstCategories_SelectedIndexChanged)
cat.Font.Size = 12
categories.Controls.Add(cat)
contents.Controls.Add(categories)
Dim brands As New Panel
brands.CssClass = "menubrandpanel"
Dim b As New Label
b.ForeColor = System.Drawing.ColorTranslator.FromHtml("#6B6B6B")
b.Font.Size = 14
b.Font.Bold = True
b.Text = "TOP BRANDS"
brands.Controls.Add(b)
Dim bnd As New RadListBox
bnd.CssClass = "menucategorylist"
Using dbContext As New familia.OpenAccess.EntitiesModel
bnd.DataSource = dbContext.ProductBrands.Where(Function(c) c.TopBrand = True And c.ProductCategories.Any(Function(r) r.CategoryID = room.CategoryID))
bnd.DataTextField = "BrandName"
bnd.DataValueField = "BrandID"
bnd.Width = 231
bnd.DataBind()
End Using
bnd.Font.Size = 12
brands.Controls.Add(bnd)
contents.Controls.Add(brands)
Dim bottom As New Panel
bottom.CssClass = "menucategorybottom"
Dim bimg As New RadBinaryImage
bimg.ImageUrl = "/images/layout/brand.png"
bimg.ResizeMode = BinaryImageResizeMode.Fit
bimg.Width = 20
bimg.Height = 20
bimg.CssClass = "buttonimage"
bottom.Controls.Add(bimg)
Dim brand As New RadButton
brand.ButtonType = RadButtonType.LinkButton
brand.CssClass = "brandbutton"
brand.Font.Bold = True
brand.Font.Size = 10
brand.Text = "All Brands"
bottom.Controls.Add(brand)
Dim bdimg As New RadBinaryImage
bdimg.ImageUrl = "/images/layout/BestDeals.png"
bdimg.ResizeMode = BinaryImageResizeMode.Fit
bdimg.Width = 20
bdimg.Height = 20
bdimg.CssClass = "buttonimage"
bottom.Controls.Add(bdimg)
Dim deals As New RadButton
deals.ButtonType = RadButtonType.LinkButton
deals.CssClass = "brandbutton"
deals.Font.Bold = True
deals.Font.Size = 10
deals.Text = "Best Deals"
bottom.Controls.Add(deals)
Dim psimg As New RadBinaryImage
psimg.ImageUrl = "/images/layout/Premimum.png"
psimg.ResizeMode = BinaryImageResizeMode.Fit
psimg.Width = 20
psimg.Height = 20
psimg.CssClass = "buttonimage"
bottom.Controls.Add(psimg)
Dim pre As New RadButton
pre.ButtonType = RadButtonType.LinkButton
pre.CssClass = "brandbutton"
pre.Font.Bold = True
pre.Font.Size = 10
pre.Text = "Premium Selections"
bottom.Controls.Add(pre)
Dim nimg As New RadBinaryImage
nimg.ImageUrl = "/images/layout/new.png"
nimg.ResizeMode = BinaryImageResizeMode.Fit
nimg.Width = 20
nimg.Height = 20
nimg.CssClass = "buttonimage"
bottom.Controls.Add(nimg)
Dim ne As New RadButton
ne.ButtonType = RadButtonType.LinkButton
ne.CssClass = "brandbutton"
ne.Font.Bold = True
ne.Font.Size = 10
ne.Text = "Recently Added"
bottom.Controls.Add(ne)
contents.Controls.Add(bottom)
End Sub
Private Sub lstCategories_SelectedIndexChanged(sender As Object, e As System.EventArgs)
End Sub
#End Region
End Class