private void SetDefaultItemValues(DataItem item) { PropertyInfo[] properties = typeof(DataItem).GetProperties(); foreach (DataField fld in item.DataCollection.DataItemFields) { try { PropertyInfo currentProperty = properties.Where(c => c.Name == fld.MappingColumn).FirstOrDefault(); if (currentProperty != null) { if (currentProperty.PropertyType == typeof(string)) { currentProperty.SetValue(item, fld.DefaultValue, null); } if (currentProperty.PropertyType == typeof(int)) { int i = 0; int.TryParse(fld.DefaultValue, out i); currentProperty.SetValue(item, i, null); } if (currentProperty.PropertyType == typeof(DateTime)) { DateTime d = DateTime.Now; DateTime.TryParse(fld.DefaultValue, out d); currentProperty.SetValue(item, d, null); } if (currentProperty.PropertyType == typeof(DataLookupValue)) { DataLookupValue dlv = DataLookupValue.GetFirst <DataLookupValue>(" Name = '" + fld.DefaultValue + "'"); if (dlv != null) { currentProperty.SetValue(item, dlv, null); } } } } catch (Exception ex) { } } }