/// <summary> /// 设置表单数据 /// </summary> public static void SetForm <T>(Page Ucontrol, T enity, string prefix) { foreach (PropertyInfo p in typeof(T).GetProperties()) { Control ctrl = FindControl(Ucontrol, prefix + p.Name); if (ctrl != null) { string value = string.Empty; if (p.GetValue(enity, null) != null) { if (p.PropertyType == typeof(DateTime) || p.PropertyType == typeof(DateTime?)) { value = p.GetValue(enity, null).ToString().Trim(); if (!string.IsNullOrEmpty(value)) { value = DateTime.Parse(value).ToString("yyyy-MM-dd"); } } else { value = p.GetValue(enity, null).ToString().Trim(); } } else { continue; } WebControlValue.SetValue(ctrl, value); } } }
/// <summary> /// 取得表单数据 /// </summary> public static void GetForm <T>(Page Ucontrol, T entity, string prefix) { foreach (PropertyInfo p in typeof(T).GetProperties()) { Control ctrl = FindControl(Ucontrol, prefix + p.Name); if (ctrl != null) { object value = WebControlValue.GetValue(ctrl); SetPropertyValue <T>(p, value.ToString(), entity); } } }
/// <summary> /// 取得表单数据 /// </summary> public static void GetForm <T>(UserControl Ucontrol, T entity, string prefix) { foreach (PropertyInfo p in typeof(T).GetProperties()) { Control ctrl = Ucontrol.FindControl(prefix + p.Name); if (ctrl != null) { //Trace.Write(" not null ,type = "+ ctrl.GetType().Name); object value = WebControlValue.GetValue(ctrl); SetPropertyValue <T>(p, value.ToString(), entity); } //Trace.WriteLine(""); } }
/// <summary> /// 设置表单数据 /// </summary> public static void SetForm <T>(UserControl Ucontrol, T enity, string prefix) { foreach (PropertyInfo p in typeof(T).GetProperties()) { Control ctrl = Ucontrol.FindControl(prefix + p.Name); if (ctrl != null) { string value = string.Empty; if (p.GetValue(enity, null) != null) { value = p.GetValue(enity, null).ToString().Trim(); } else { continue; } WebControlValue.SetValue(ctrl, value); } } }