Collections in Composite Controls RRS feed

  • Question

  • User-1206010574 posted

    I have a composite custom control which amongst other things contains a drop down list. Currently the drop down list is populated from an xml file, the path of which can be specfied in the tag.

    What I would like to do is have a collection property which is populated from the tag as so:

    <custom:Control ID="CustomControl" runat="server">
        <item value="some_value">Item 1</item>
        <item value="some_value">Item 2</item>

     How should I go about putting together the VB code to do this? I assume I need some kind of public property, but of what type?

    Any tutorials/help gratefully received.

    Monday, April 14, 2008 2:30 PM


  • User-16411453 posted

     You need a file call Collections.vb or cs


    Imports System
    Imports System.Collections.Generic
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Text
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Drawing.Design
    Imports System.Web.UI.Design

    Namespace Horizontal_MenuControl

    Public Class MenuItems

    Private _MenuItem_Name As String

    <Category("MenuItems")> _
    <Description("Name of Menu Item")> _
    <NotifyParentProperty(True)> _
    <RefreshProperties(RefreshProperties.Repaint)> _
    Public Property Name() As String

    Return CType
    (_MenuItem_Name, String)
    End Get

    (ByVal value As String)
    _MenuItem_Name = value
    End Set

    End Property

    End Class

    End Namespace
    and this in the control file
    Private _MenuItems As MenuItems = New MenuItems

    <Bindable(True)> _
    <Category("Menu Control")> _
    <Description("Enter and program your menu items here, to be displayed by the menu control")> _
    <RefreshProperties(RefreshProperties.Repaint)> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public ReadOnly Property Horizontal_MenuItems() As MenuItems

    End Get

    End Property
     This is how you access the collection
    Dim MenuItemArray As MenuItems = Horizontal_MenuItems
    Dim MenuItem_Count As Integer = MenuItemArray.GetCount()
    Dim idx As Integer = 0
    For idx = 0 To MenuItem_Count - 1
    _MenuItem_Name = MenuItemArray.Item(idx).Name
    _MenuItem_Value = MenuItemArray.Item(idx).Value


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2008 8:02 PM