/// <summary> /// Page页面中的控件 自动绑定到 实体Model字段数据 /// </summary> protected void Page2Model(DbObjectBase model) { PropertyDescriptorCollection modelProperties = TypeDescriptor.GetProperties(model); //Response.Clear(); foreach (PropertyDescriptor pd in modelProperties) { string ctrlName = string.Format("{0}{1}", this.ControlNamePrefix, pd.Name); WebControl ctl = (WebControl)PageHelper.GetWebControl(this.Page, ctrlName); if (ctl != null) { object value = ctl.GetValue(); pd.SetValue(model, value); } } }
/// <summary> /// 实体Model字段数据自动绑定到Page页面中的控件 /// </summary> protected void Model2Page(DbObjectBase model) { PropertyDescriptorCollection modelProperties = TypeDescriptor.GetProperties(model); foreach (PropertyDescriptor pd in modelProperties) { string ctrlName = string.Format("{0}{1}", this.ControlNamePrefix, pd.Name); WebControl ctl = (WebControl)PageHelper.GetWebControl(this.Page, ctrlName); if (ctl != null) { object value = pd.GetValue(model); if (value != null) { ctl.SetValue(value.ToString()); } } } }