How to access controls inside Radmenu Dynamic Template

3 posts, 0 answers
  1. Zafar
    Zafar avatar
    5 posts
    Member since:
    Feb 2012

    Posted 09 Mar 2012 Link to this post

    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)
                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
                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
                    Dim mainmenuItemTemplate As New MainMenuItemTemplate()
                    Dim childItem As New RadMenuItem()
                    childItem.CssClass = "mainmenudropdown"
                    childItem.ItemTemplate = New MenuItemTemplate()
            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"

            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


            Dim cat As New RadListBox

            cat.CssClass = "menucategorylist"
            Using dbContext As New familia.OpenAccess.EntitiesModel
                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

          End Using
           AddHandler cat.SelectedIndexChanged, New EventHandler(AddressOf lstCategories_SelectedIndexChanged)
            cat.Font.Size = 12


            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"


            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
            End Using

            bnd.Font.Size = 12


            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"
            Dim brand As New RadButton
            brand.ButtonType = RadButtonType.LinkButton
            brand.CssClass = "brandbutton"
            brand.Font.Bold = True
            brand.Font.Size = 10
            brand.Text = "All Brands"

            Dim bdimg As New RadBinaryImage
            bdimg.ImageUrl = "/images/layout/BestDeals.png"
            bdimg.ResizeMode = BinaryImageResizeMode.Fit
            bdimg.Width = 20
            bdimg.Height = 20
            bdimg.CssClass = "buttonimage"


            Dim deals As New RadButton
            deals.ButtonType = RadButtonType.LinkButton

            deals.CssClass = "brandbutton"
            deals.Font.Bold = True
            deals.Font.Size = 10
            deals.Text = "Best 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"


            Dim pre As New RadButton
            pre.ButtonType = RadButtonType.LinkButton
            pre.CssClass = "brandbutton"
            pre.Font.Bold = True
            pre.Font.Size = 10
            pre.Text = "Premium Selections"

            Dim nimg As New RadBinaryImage
            nimg.ImageUrl = "/images/layout/new.png"
            nimg.ResizeMode = BinaryImageResizeMode.Fit
            nimg.Width = 20
            nimg.Height = 20
            nimg.CssClass = "buttonimage"


            Dim ne As New RadButton
            ne.ButtonType = RadButtonType.LinkButton
            ne.CssClass = "brandbutton"
            ne.Font.Bold = True
            ne.Font.Size = 10
            ne.Text = "Recently Added"

      End Sub

        Private Sub lstCategories_SelectedIndexChanged(sender As Object, e As System.EventArgs)

        End Sub
    #End Region
    End Class
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Mar 2012 Link to this post


    Try the following code.
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        Dim template As New TextBoxTemplate()
        For Each item As RadMenuItem In RadMenu1.GetAllItems()
            If item.Level > 0 Then
            End If
    End Sub
    Protected Sub RadMenu1_ItemClick(sender As Object, e As RadMenuEventArgs)
        If RadMenu1.SelectedItem.Level > 0 Then
            Dim listbox As RadListBox = DirectCast(RadMenu1.SelectedItem.FindControl("RadListBox1"), RadListBox)
            Dim s As String = listbox.SelectedValue
        End If
    End Sub
     Class TextBoxTemplate
        Implements ITemplate
        Public Sub InstantiateIn(container As Control)
            Dim RadListBox1 As New RadListBox()
            RadListBox1.ID = "RadListBox1"
            RadListBox1.AutoPostBack = True
            RadListBox1.SelectedIndexChanged += New EventHandler(RadListBox1_SelectedIndexChanged)
            RadListBox1.DataTextField = "EmployeeID"
            RadListBox1.DataValueField = "EmployeeID"
            RadListBox1.DataSourceID = "SqlDataSource1"
        End Sub
        Private Sub RadListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
            Dim lst As RadListBox = DirectCast(sender, RadListBox)
            Dim ee As String = lst.SelectedValue
        End Sub
    End Class

  3. DevCraft R3 2016 release webinar banner
  4. Zafar
    Zafar avatar
    5 posts
    Member since:
    Feb 2012

    Posted 09 Mar 2012 Link to this post

    Thanks for the reply. The code provided by you is not working. Please review the code posted by me and suggest a solution. thanks

    Instead of using template I have also tried adding controls to controls collection of radmenuitem in Page_PreRender event but when I try access  controls collection in radmenu itemclick event, its show zero controls. Suggest a solution please.
Back to Top