English 中文(简体)
我如何控制在伙伴关系中的儿童保护收集工作。 净额
原标题:How do I make a control with a child control collection in ASP.Net

I m 试图为蚊帐开发一种海关控制,其标记如下:

<bk:ControlMenu ID="cmTest" runat="server" Width="400px">               
    <Items>
        <asp:Textbox>
        <asp:Checkbox>
        [ List of controls... ]
    </Items>
</bk:ControlMenu>

当我发展我的控制权时,我能做些什么? (所涉物项的收集部分)。

最佳回答

在标准用户网络控制中,你可以把一些内容放开。 你们需要开发一种海关服务器控制,以实现这一目标。 为了允许海关服务器控制中包含的内容,你需要使用<代码>PersistenceMode属性,并将其设定为InnerProperty

/// <summary>
/// Gets the columns collection.
/// </summary>
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ItemCollection Items
{
    get
    {
        if (itemCollection == null)
        {
            if (itemArrayList == null)
            {
                this.EnsureChildControls();
                if (itemArrayList == null)
                    itemArrayList = new ArrayList();
            }
            itemCollection = new ItemCollection(itemArrayList);
        }
        return itemCollection;
    }
}

Here s an example from a control that I created:

http://www.ohchr.org。

/// <summary>
/// Gets the columns collection.
/// </summary>
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ScheduleGridColumnCollection Columns
{
    get
    {
        if (scheduleColumnsCollection == null)
        {
            if (scheduleColumnsArrayList == null)
            {
                this.EnsureChildControls();
                if (scheduleColumnsArrayList == null)
                    scheduleColumnsArrayList = new ArrayList();
            }
            scheduleColumnsCollection = new ScheduleGridColumnCollection(scheduleColumnsArrayList);
        }
        return scheduleColumnsCollection;
    }
}

#region schedule column

[PersistChildren(true)]
public sealed class ScheduleGridColumn : DataGridColumn, INamingContainer
{
    #region private member variables

    private bool editModeEnabled;
    private bool aggregateColumn;        

    private string uniqueName;
    private string dataFieldName;
    private string aggregateKey;
    private string dataFormatString;

    private ITemplate editTemplate = null;

    #endregion

    #region constructor

    /// <summary>
    /// Initializes the GridColumn object using default values.
    /// </summary>
    public ScheduleGridColumn()
    {
        //initialize other fields to defaults
        dataFieldName = String.Empty;
        dataFormatString = String.Empty;
        uniqueName = String.Empty;

        //disable edit mode by default
        editModeEnabled = false;
    }

    #endregion

    #region properties

    /// <summary>
    /// Gets or sets the edit template.
    /// </summary>      
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
    PersistenceMode(PersistenceMode.InnerProperty),
    TemplateInstance(TemplateInstance.Single)]
    public ITemplate EditTemplate
    {
        get
        {
            return editTemplate;
        }
        set
        {
            editTemplate = value;
        }
    }

    /// <summary>
    /// Gets or sets the unique name.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string UniqueName
    {
        get
        {
            return uniqueName;
        }
        set
        {
            uniqueName = value;
        }
    }

    /// <summary>
    /// Gets or sets the name of the data field.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string DataField
    {
        get
        {
            return dataFieldName;
        }
        set
        {
            dataFieldName = value;
        }
    }

    /// <summary>
    /// Gets or sets the format string used to format the data.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string DataFormatString
    {
        get
        {
            return dataFormatString;
        }
        set
        {
            dataFormatString = value;
        }
    }

    /// <summary>
    /// Gets or sets a value indicating whether the item 
    /// is in edit mode.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool EditModeEnabled
    {
        get
        {
            return editModeEnabled;
        }
        set
        {
            editModeEnabled = value;
        }
    }

    /// <summary>
    /// Gets or sets a value indicating whether the item should be aggregated.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool AggregateColumn
    {
        get
        {
            return aggregateColumn;
        }
        set
        {
            aggregateColumn = value;
        }
    }

    /// <summary>
    /// Gets or sets the aggregate key.
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string AggregateKey
    {
        get
        {
            return aggregateKey;
        }
        set
        {
            aggregateKey = value;
        }
    }

    #endregion
}

#endregion

#region schedule column collection

[PersistChildren(true)]
public sealed class ScheduleGridColumnCollection : ICollection
{
    #region member variables

    private ArrayList ItemArray;
    private string columnGroupTitle;

    #endregion

    #region constructors

    public ScheduleGridColumnCollection(ArrayList items)
    {
        ItemArray = items;
    }

    #endregion

    #region methods

    /// <summary>
    /// Finds the column corresponding to the data field.
    /// </summary>
    /// <param name="DataFieldName"></param>
    /// <returns></returns>
    public ScheduleGridColumn FindColumnDataField(string dataFieldName)
    {
        ScheduleGridColumn column = new ScheduleGridColumn();
        foreach (ScheduleGridColumn item in ItemArray.Cast<ScheduleGridColumn>())
        {
            if (item.DataField == dataFieldName)
            {
                column = item;
                break;
            }
        }
        return column;
    }

    public bool ContainsColumnWithDataField(string dataFieldName)
    {
        foreach (ScheduleGridColumn item in ItemArray.Cast<ScheduleGridColumn>())
            if (item.DataField == dataFieldName)
                return true;
        return false;
    }

    /// <summary>
    /// Adds an item to the collection.
    /// </summary>
    /// <param name="item"></param>
    public void Add(ScheduleGridColumn item)
    {
        ItemArray.Add(item);
    }

    public void AddRange(ScheduleGridColumnCollection itemCollection)
    {
        foreach (ScheduleGridColumn item in itemCollection)
            ItemArray.Add(item);
    }

    /// <summary>
    /// Clears all items from the collection.
    /// </summary>
    public void Clear()
    {
        ItemArray.Clear();
    }

    /// <summary>
    /// Returns the enumerated equivalent of the collection.
    /// </summary>
    /// <returns></returns>
    public IEnumerator GetEnumerator()
    {
        return ItemArray.GetEnumerator();
    }

    /// <summary>
    /// Copies the collection to the array parameter.
    /// </summary>
    /// <param name="array"></param>
    /// <param name="index"></param>
    public void CopyTo(Array array, int index)
    {
        ItemArray.CopyTo(array, index);
    }  

    #endregion

    #region properties

    /// <summary>
    /// Gets the schedule column located at the specified index.
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public ScheduleGridColumn this[int index]
    {
        get
        {
            return (ScheduleGridColumn)ItemArray[index];
        }
    }

    /// <summary>
    /// Gets a schedule column from the collection based on a unique name.
    /// </summary>
    /// <param name="uniqueName"></param>
    /// <returns></returns>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public ScheduleGridColumn this[string uniqueName]
    {
        get
        {
            ScheduleGridColumn dataColumn = null;
            foreach (object item in ItemArray)
                if (((ScheduleGridColumn)item).UniqueName == uniqueName)
                    dataColumn = (ScheduleGridColumn)item;
            return dataColumn;
        }
    }

    /// <summary>
    /// Gets the total number of items in the collection.
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public int Count
    {
        get
        {
            return ItemArray.Count;
        }
    }

    /// <summary>
    /// Gets a value indicating whether the collection is read only.
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public bool IsReadOnly
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// Gets a value indicating whether the collection is synchronized.
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public bool IsSynchronized
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// Gets the sync root object.
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public object SyncRoot
    {
        get
        {
            return this;
        }
    }

    /// <summary>
    /// Gets or sets the column group title.
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Browsable(true)]
    public string ColumnGroupTitle
    {
        get
        {
            return columnGroupTitle;
        }
        set
        {
            columnGroupTitle = value;
        }
    }

    #endregion
}

#endregion
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签