/// <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 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); } } }