Ejemplo n.º 1
0
        /// <summary>
        /// Writes the data in the given entity object to the given form
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="form"></param>
        public static void EntityToForm(object entity, System.Web.UI.Control form)
        {
            PropertyInfo[] properties = entity.GetType().GetProperties();

            //loop the properties of the entity, try to find a matching webcontrol for each one
            foreach (var property in properties)
            {
                var control = WebControlManager.GetControl(property.Name, form);

                if (control != null)
                {
                    var value = property.GetValue(entity, null);
                    if (value != null)
                    {
                        WebControlManager.SetValue(control, value.ToString());
                    }
                }
            }
        }