コード例 #1
0
ファイル: MxDataGrid.cs プロジェクト: ikvm/webmatrix
 private ArrayList CreateAutoGeneratedFields(PagedDataSource dataSource)
 {
     if (dataSource == null)
     {
         return null;
     }
     ArrayList list = new ArrayList();
     PropertyDescriptorCollection itemProperties = null;
     bool flag = true;
     itemProperties = dataSource.GetItemProperties(new PropertyDescriptor[0]);
     if (itemProperties == null)
     {
         Type propertyType = null;
         object firstDataItem = null;
         PropertyInfo info = dataSource.DataSource.GetType().GetProperty("Item", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, null, new Type[] { typeof(int) }, null);
         if (info != null)
         {
             propertyType = info.PropertyType;
         }
         if ((propertyType == null) || (propertyType == typeof(object)))
         {
             IEnumerator enumerator = dataSource.GetEnumerator();
             if (enumerator.MoveNext())
             {
                 firstDataItem = enumerator.Current;
             }
             else
             {
                 flag = false;
             }
             if (firstDataItem != null)
             {
                 propertyType = firstDataItem.GetType();
             }
             this.StoreEnumerator(enumerator, firstDataItem);
         }
         if ((firstDataItem != null) && (firstDataItem is ICustomTypeDescriptor))
         {
             itemProperties = TypeDescriptor.GetProperties(firstDataItem);
         }
         else if (propertyType != null)
         {
             if (BaseDataList.IsBindableType(propertyType))
             {
                 Microsoft.Matrix.Framework.Web.UI.BoundField field = new Microsoft.Matrix.Framework.Web.UI.BoundField();
                 ((IStateManager) field).TrackViewState();
                 field.HeaderText = "Item";
                 field.DataField = Microsoft.Matrix.Framework.Web.UI.BoundField.thisExpr;
                 field.SortExpression = "Item";
                 field.SetOwner(this);
                 list.Add(field);
             }
             else
             {
                 itemProperties = TypeDescriptor.GetProperties(propertyType);
             }
         }
     }
     if ((itemProperties != null) && (itemProperties.Count != 0))
     {
         foreach (PropertyDescriptor descriptor in itemProperties)
         {
             if (BaseDataList.IsBindableType(descriptor.PropertyType) && ((this.AutoGenerateExcludeFields.Length == 0) || (Array.IndexOf(this.AutoGenerateExcludeFields, descriptor.Name) == -1)))
             {
                 Microsoft.Matrix.Framework.Web.UI.BoundField field2 = new Microsoft.Matrix.Framework.Web.UI.BoundField();
                 ((IStateManager) field2).TrackViewState();
                 field2.HeaderText = descriptor.Name;
                 field2.DataField = descriptor.Name;
                 field2.SortExpression = descriptor.Name;
                 field2.ReadOnly = descriptor.IsReadOnly;
                 field2.SetOwner(this);
                 list.Add(field2);
             }
         }
     }
     if ((list.Count == 0) && flag)
     {
         throw new HttpException(string.Format(Microsoft.Matrix.Framework.SR.GetString("MxDataGrid_NoAutoGenColumns"), this.ID));
     }
     return list;
 }
コード例 #2
0
ファイル: MxDataGrid.cs プロジェクト: ikvm/webmatrix
 protected override void LoadViewState(object savedState)
 {
     if (savedState != null)
     {
         object[] objArray = (object[]) savedState;
         if (objArray[0] != null)
         {
             base.LoadViewState(objArray[0]);
         }
         if (objArray[1] != null)
         {
             ((IStateManager) this.Fields).LoadViewState(objArray[1]);
         }
         if (objArray[2] != null)
         {
             ((IStateManager) this.PagerStyle).LoadViewState(objArray[2]);
         }
         if (objArray[3] != null)
         {
             ((IStateManager) this.HeaderStyle).LoadViewState(objArray[3]);
         }
         if (objArray[4] != null)
         {
             ((IStateManager) this.FooterStyle).LoadViewState(objArray[4]);
         }
         if (objArray[5] != null)
         {
             ((IStateManager) this.ItemStyle).LoadViewState(objArray[5]);
         }
         if (objArray[6] != null)
         {
             ((IStateManager) this.AlternatingItemStyle).LoadViewState(objArray[6]);
         }
         if (objArray[7] != null)
         {
             ((IStateManager) this.SelectedItemStyle).LoadViewState(objArray[7]);
         }
         if (objArray[8] != null)
         {
             ((IStateManager) this.EditItemStyle).LoadViewState(objArray[8]);
         }
         if (objArray[9] != null)
         {
             object[] objArray2 = (object[]) objArray[9];
             int length = objArray2.Length;
             if (length != 0)
             {
                 this.autoGenFieldsArray = new ArrayList();
             }
             else
             {
                 this.autoGenFieldsArray = null;
             }
             for (int i = 0; i < length; i++)
             {
                 Microsoft.Matrix.Framework.Web.UI.BoundField field = new Microsoft.Matrix.Framework.Web.UI.BoundField();
                 ((IStateManager) field).TrackViewState();
                 ((IStateManager) field).LoadViewState(objArray2[i]);
                 field.SetOwner(this);
                 this.autoGenFieldsArray.Add(field);
             }
         }
     }
 }