File: DataControlFieldCollection.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (215 lines) | stat: -rw-r--r-- 7,578 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//------------------------------------------------------------------------------
// <copyright file="DataControlFieldCollection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls {

    using System;
    using System.Collections;
    using System.ComponentModel;

    /// <devdoc>
    /// <para>Represents the collection of fields to be displayed in 
    /// a data bound control that uses fields.</para>
    /// </devdoc>
    public sealed class DataControlFieldCollection : StateManagedCollection {

        private static readonly Type[] knownTypes = new Type[] {
                                                                typeof(BoundField),
                                                                typeof(ButtonField),
                                                                typeof(CheckBoxField),
                                                                typeof(CommandField),
                                                                typeof(HyperLinkField),
                                                                typeof(ImageField),
                                                                typeof(TemplateField)
                                                            };
        

        public event EventHandler FieldsChanged;



        /// <devdoc>
        /// <para>Gets a <see cref='System.Web.UI.WebControls.DataControlField'/> at the specified index in the 
        /// collection.</para>
        /// </devdoc>
        [
        Browsable(false)
        ]
        public DataControlField this[int index] {
            get {
                return ((IList)this)[index] as DataControlField;
            }
        }


        /// <devdoc>
        /// <para>Appends a <see cref='System.Web.UI.WebControls.DataControlField'/> to the collection.</para>
        /// </devdoc>
        public void Add(DataControlField field) {
            ((IList)this).Add(field);
        }

        /// <devdoc>
        /// <para>Provides a deep copy of the collection.  Used mainly by design time dialogs to implement "cancel" rollback behavior.</para>
        /// </devdoc>
        public DataControlFieldCollection CloneFields() {
            DataControlFieldCollection fields = new DataControlFieldCollection();
            foreach (DataControlField field in this) {
                fields.Add(field.CloneField());
            }
            return fields;
        }


        /// <devdoc>
        /// <para>Returns whether a DataControlField is a member of the collection.</para>
        /// </devdoc>
        public bool Contains(DataControlField field) {
            return ((IList)this).Contains(field);
        }


        /// <devdoc>
        /// <para>Copies the contents of the entire collection into an <see cref='System.Array' qualify='true'/> appending at 
        /// the specified index of the <see cref='System.Array' qualify='true'/>.</para>
        /// </devdoc>
        public void CopyTo(DataControlField[] array, int index) {
            ((IList)this).CopyTo(array, index);
            return;
        }


        /// <devdoc>
        /// <para>Creates a known type of DataControlField.</para>
        /// </devdoc>
        protected override object CreateKnownType(int index) {
             switch (index) {
                 case 0:
                     return new BoundField();
                 case 1:
                     return new ButtonField();
                 case 2:
                     return new CheckBoxField();
                 case 3:
                     return new CommandField();
                 case 4:
                     return new HyperLinkField();
                 case 5:
                     return new ImageField();
                 case 6:
                     return new TemplateField();
                 default:
                     throw new ArgumentOutOfRangeException(SR.GetString(SR.DataControlFieldCollection_InvalidTypeIndex));
            }        
        }


        /// <devdoc>
        /// <para>Returns an ArrayList of known DataControlField types.</para>
        /// </devdoc>
        protected override Type[] GetKnownTypes() {
            return knownTypes;
        }


        /// <devdoc>
        /// <para>Returns the index of the first occurrence of a value in a <see cref='System.Web.UI.WebControls.DataControlField'/>.</para>
        /// </devdoc>
        public int IndexOf(DataControlField field) {
            return ((IList)this).IndexOf(field);
        }


        /// <devdoc>
        /// <para>Inserts a <see cref='System.Web.UI.WebControls.DataControlField'/> to the collection 
        /// at the specified index.</para>
        /// </devdoc>
        public void Insert(int index, DataControlField field) {
            ((IList)this).Insert(index, field);
        }


        /// <devdoc>
        /// Called when the Clear() method is complete.
        /// </devdoc>
        protected override void OnClearComplete() { 
            OnFieldsChanged();
        }
        
        /// <devdoc>
        /// </devdoc>
        void OnFieldChanged(object sender, EventArgs e) {
            OnFieldsChanged();
        }

        /// <devdoc>
        /// </devdoc>
        void OnFieldsChanged() {
            if (FieldsChanged != null) {
                FieldsChanged(this, EventArgs.Empty);
            }
        }


        /// <devdoc>
        /// Called when the Insert() method is complete.
        /// </devdoc>
        protected override void OnInsertComplete(int index, object value) { 
            DataControlField field = value as DataControlField;
            if (field != null) {
                field.FieldChanged += new EventHandler(OnFieldChanged);
            }
            OnFieldsChanged();
        }


        /// <devdoc>
        /// Called when the Remove() method is complete.
        /// </devdoc>
        protected override void OnRemoveComplete(int index, object value) { 
            DataControlField field = value as DataControlField;
            if (field != null) {
                field.FieldChanged -= new EventHandler(OnFieldChanged);
            }
            OnFieldsChanged();
        }


        /// <devdoc>
        /// <para>Validates that an object is a HotSpot.</para>
        /// </devdoc>
        protected override void OnValidate(object o) {
            base.OnValidate(o);
            if (!(o is DataControlField))
                throw new ArgumentException(SR.GetString(SR.DataControlFieldCollection_InvalidType));
        }


        /// <devdoc>
        /// <para>Removes a <see cref='System.Web.UI.WebControls.DataControlField'/> from the collection at the specified 
        /// index.</para>
        /// </devdoc>
        public void RemoveAt(int index) {
            ((IList)this).RemoveAt(index);
        }


        /// <devdoc>
        /// <para>Removes the specified <see cref='System.Web.UI.WebControls.DataControlField'/> from the collection.</para>
        /// </devdoc>
        public void Remove(DataControlField field) {
            ((IList)this).Remove(field);
        }


        /// <devdoc>
        /// <para>Marks a DataControlField as dirty so that it will record its entire state into view state.</para>
        /// </devdoc>
        protected override void SetDirtyObject(object o) {
            ((DataControlField)o).SetDirty();
        }
    }
}