本文整理汇总了C#中System.Web.UI.WebControls.PagedDataSource.GetItemProperties方法的典型用法代码示例。如果您正苦于以下问题:C# PagedDataSource.GetItemProperties方法的具体用法?C# PagedDataSource.GetItemProperties怎么用?C# PagedDataSource.GetItemProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.PagedDataSource
的用法示例。
在下文中一共展示了PagedDataSource.GetItemProperties方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoCreateColumns
/// <summary>
/// Generates the columns when AutoGenerateColumns is true.
/// This method is called by CreateColumnSet when dataSource
/// is to be used and columns need to be generated automatically.
/// </summary>
private ArrayList AutoCreateColumns (PagedDataSource source)
{
if (source == null)
return null;
ArrayList retVal = null;
PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor [0]);
bool empty_enumerator = false;
Type prop_type;
BoundColumn col;
if (props == null) {
object fitem = null;
prop_type = null;
PropertyInfo prop_item = source.DataSource.GetType ().GetProperty ("Item",
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
null, null, new Type[] { typeof(int) }, null);
if (prop_item != null)
prop_type = prop_item.PropertyType;
if (prop_type == null || prop_type == typeof (object)) {
IEnumerator en = source.GetEnumerator();
if (en.MoveNext ()) {
fitem = en.Current;
if (fitem != null)
prop_type = fitem.GetType ();
} else {
empty_enumerator = true;
}
StoreEnumerator (en, fitem);
}
if (fitem is ICustomTypeDescriptor) {
props = TypeDescriptor.GetProperties (fitem);
} else if (prop_type != null) {
if (IsBindableType (prop_type)) {
col = new BoundColumn ();
((IStateManager) col).TrackViewState ();
col.HeaderText = "Item";
col.SortExpression = "Item";
col.DataField = BoundColumn.thisExpr;
col.SetOwner (this);
if (retVal == null)
retVal = new ArrayList ();
retVal.Add (col);
} else {
props = TypeDescriptor.GetProperties (prop_type);
}
}
}
if (props != null && props.Count > 0) {
try {
foreach (PropertyDescriptor current in props) {
if (!IsBindableType (current.PropertyType))
continue;
col = new BoundColumn ();
((IStateManager) col).TrackViewState ();
string name = current.Name;
col.HeaderText = name;
col.SortExpression = name;
col.DataField = name;
col.ReadOnly = current.IsReadOnly;
col.SetOwner (this);
if (retVal == null)
retVal = new ArrayList ();
retVal.Add (col);
}
} finally {
if (props is IDisposable)
((IDisposable) props).Dispose ();
}
}
if (retVal != null && retVal.Count > 0)
return retVal;
if (empty_enumerator)
return null;
throw new HttpException (HttpRuntime.FormatResourceString ("DataGrid_NoAutoGenColumns", ID));
}
示例2: CreateAutoFieldProperties
AutoGeneratedFieldProperties[] CreateAutoFieldProperties (PagedDataSource source)
{
if(source == null) return null;
PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor[0]);
Type prop_type;
ArrayList retVal = new ArrayList();
if (props == null)
{
object fitem = null;
prop_type = null;
PropertyInfo prop_item = source.DataSource.GetType().GetProperty("Item",
BindingFlags.Instance | BindingFlags.Static |
BindingFlags.Public, null, null,
new Type[] { typeof(int) }, null);
if (prop_item != null) {
prop_type = prop_item.PropertyType;
}
if (prop_type == null || prop_type == typeof(object)) {
IEnumerator en = source.GetEnumerator();
if (en != null && en.MoveNext ()) {
fitem = en.Current;
_dataEnumerator = en;
}
if (fitem != null)
prop_type = fitem.GetType();
}
if (fitem != null && fitem is ICustomTypeDescriptor) {
props = TypeDescriptor.GetProperties(fitem);
} else if (prop_type != null) {
if (IsBindableType (prop_type)) {
AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
((IStateManager)field).TrackViewState();
field.Name = "Item";
field.DataField = BoundField.ThisExpression;
field.Type = prop_type;
retVal.Add (field);
} else {
props = TypeDescriptor.GetProperties (prop_type);
}
}
}
if (props != null && props.Count > 0)
{
foreach (PropertyDescriptor current in props) {
if (IsBindableType (current.PropertyType)) {
AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
((IStateManager)field).TrackViewState();
field.Name = current.Name;
field.DataField = current.Name;
for (int i = 0; i < DataKeyNames.Length; i++) {
if (string.Compare (DataKeyNames [i], current.Name, StringComparison.InvariantCultureIgnoreCase) == 0) {
field.IsReadOnly = true;
break;
}
}
field.Type = current.PropertyType;
retVal.Add (field);
}
}
}
if (retVal.Count > 0)
return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
else
return new AutoGeneratedFieldProperties [0];
}
示例3: CreateAutoGeneratedColumns
private ArrayList CreateAutoGeneratedColumns(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.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))
{
BoundColumn column = new BoundColumn();
((IStateManager) column).TrackViewState();
column.HeaderText = "Item";
column.DataField = BoundColumn.thisExpr;
column.SortExpression = "Item";
column.SetOwner(this);
list.Add(column);
}
else
{
itemProperties = TypeDescriptor.GetProperties(propertyType);
}
}
}
if ((itemProperties != null) && (itemProperties.Count != 0))
{
foreach (PropertyDescriptor descriptor in itemProperties)
{
if (BaseDataList.IsBindableType(descriptor.PropertyType))
{
BoundColumn column2 = new BoundColumn();
((IStateManager) column2).TrackViewState();
column2.HeaderText = descriptor.Name;
column2.DataField = descriptor.Name;
column2.SortExpression = descriptor.Name;
column2.ReadOnly = descriptor.IsReadOnly;
column2.SetOwner(this);
list.Add(column2);
}
}
}
if ((list.Count == 0) && flag)
{
throw new HttpException(System.Web.SR.GetString("DataGrid_NoAutoGenColumns", new object[] { this.ID }));
}
return list;
}
示例4: CreateColumnSet
protected virtual ArrayList CreateColumnSet (PagedDataSource dataSource, bool useDataSource)
{
ArrayList res = new ArrayList ();
if (columns_list != null)
res.AddRange (columns_list);
if (AutoGenerateColumns) {
if (useDataSource) {
data_enumerator = null;
PropertyDescriptorCollection props = dataSource.GetItemProperties (null);
DataSourceColumns.Clear ();
if (props != null) {
foreach (PropertyDescriptor d in props)
AddPropertyToColumns (d, false);
} else {
AddColumnsFromSource (dataSource);
}
}
if (data_source_columns != null && data_source_columns.Count > 0)
res.AddRange (data_source_columns);
}
return res;
}
示例5: GetItemProperties
public void GetItemProperties ()
{
PagedDataSource ds = new PagedDataSource ();
DataTable table = new DataTable ();
table.Columns.Add (new DataColumn ("one", typeof (string)));
table.Columns.Add (new DataColumn ("two", typeof (string)));
table.Columns.Add (new DataColumn ("three", typeof (string)));
ds.DataSource = new DataView (table);
PropertyDescriptorCollection props = ds.GetItemProperties (null);
Assert.AreEqual (props.Count, 3, "A1");
Assert.AreEqual (props [0].Name, "one", "A2");
Assert.AreEqual (props [1].Name, "two", "A3");
Assert.AreEqual (props [2].Name, "three", "A4");
ds.DataSource = new ArrayList ();
props = ds.GetItemProperties (null);
Assert.AreEqual (props, null, "A5");
}
示例6: CreateAutoGeneratedColumns
private ICollection CreateAutoGeneratedColumns(PagedDataSource dataSource)
{
if (dataSource == null)
{
return null;
}
ArrayList list = new ArrayList();
this._autoGenFieldProps = new ArrayList();
PropertyDescriptorCollection itemProperties = null;
bool flag = true;
itemProperties = dataSource.GetItemProperties(new PropertyDescriptor[0]);
if (itemProperties == null)
{
Type propertyType = null;
object firstDataRow = null;
PropertyInfo info = dataSource.DataSource.GetType().GetProperty("Item", BindingFlags.Public | 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())
{
firstDataRow = enumerator.Current;
}
else
{
flag = false;
}
if (firstDataRow != null)
{
propertyType = firstDataRow.GetType();
}
this.StoreEnumerator(enumerator, firstDataRow);
}
if ((firstDataRow != null) && (firstDataRow is ICustomTypeDescriptor))
{
itemProperties = TypeDescriptor.GetProperties(firstDataRow);
}
else if (propertyType != null)
{
if (this.IsBindableType(propertyType))
{
AutoGeneratedFieldProperties fieldProperties = new AutoGeneratedFieldProperties();
((IStateManager) fieldProperties).TrackViewState();
fieldProperties.Type = propertyType;
fieldProperties.Name = "Item";
fieldProperties.DataField = BoundField.ThisExpression;
AutoGeneratedField field = this.CreateAutoGeneratedColumn(fieldProperties);
if (field != null)
{
list.Add(field);
this._autoGenFieldProps.Add(fieldProperties);
}
}
else
{
itemProperties = TypeDescriptor.GetProperties(propertyType);
}
}
}
else if (itemProperties.Count == 0)
{
flag = false;
}
if ((itemProperties != null) && (itemProperties.Count != 0))
{
string[] dataKeyNames = this.DataKeyNames;
int length = dataKeyNames.Length;
string[] strArray2 = new string[length];
for (int i = 0; i < length; i++)
{
strArray2[i] = dataKeyNames[i].ToLowerInvariant();
}
foreach (PropertyDescriptor descriptor in itemProperties)
{
Type type = descriptor.PropertyType;
if (this.IsBindableType(type))
{
string name = descriptor.Name;
bool flag2 = strArray2.Contains(name.ToLowerInvariant());
AutoGeneratedFieldProperties properties2 = new AutoGeneratedFieldProperties();
((IStateManager) properties2).TrackViewState();
properties2.Name = name;
properties2.IsReadOnly = flag2;
properties2.Type = type;
properties2.DataField = name;
AutoGeneratedField field2 = this.CreateAutoGeneratedColumn(properties2);
if (field2 != null)
{
list.Add(field2);
this._autoGenFieldProps.Add(properties2);
}
}
}
}
if ((list.Count == 0) && flag)
{
//.........这里部分代码省略.........
示例7: CreateAutoGeneratedFields
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;
}