/// <summary> /// Binds the specified list of business objects to the specified <see cref="System.Web.UI.Control"/> /// or its child <see cref="System.Web.UI.Control"/> using the specified list of /// control binders. /// </summary> /// <param name="c">The <see cref="System.Web.UI.Control"/> or the child /// <see cref="System.Web.UI.Control"/> of which is to bind to.</param> /// <param name="bindableObjects">The list of business objects to bind.</param> /// <param name="controlBinders">The list of control binders used to bind.</param> /// <param name="p"></param> private void BindToList(Control c, IEnumerable bindableObjects, Dictionary<string, List<IControlBinder>> controlBinders, params object[] p) { if (c == null) return; Dictionary<string, Control> dictionary = c.GetControls(); foreach (string key in controlBinders.Keys) { // First, check if the control itself needs to be bound if (c.ID.StartsWith(key)) { foreach (IControlBinder binder in controlBinders[key]) { binder.Bind(c, bindableObjects, p); } } if (bindableObjects != null) { // Next, check if there are children that need to be bound string name = key + bindableObjects.GetType().Name.Replace("[]", ""); if (!dictionary.ContainsKey(name)) continue; foreach (IControlBinder binder in _binders[key]) { binder.Bind(dictionary[name], bindableObjects); } } } }
/// <summary> /// Binds the specified business object to the specified <see cref="System.Web.UI.Control"/> /// or its child <see cref="System.Web.UI.Control"/> using the specified list of /// control binders. /// </summary> /// <param name="c">The <see cref="System.Web.UI.Control"/> or the child /// <see cref="System.Web.UI.Control"/> of which is to bind to.</param> /// <param name="bindableObject">The business object to bind.</param> /// <param name="controlBinders">The list of control binders used to bind.</param> /// <param name="p"></param> private static void BindToObject(Control c, object bindableObject, Dictionary<string, List<IControlBinder>> controlBinders, object[] p) { if (c == null || bindableObject == null) return; string domainobject = bindableObject.GetType().Name; PropertyInfo[] properties = bindableObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); Dictionary<string, Control> dictionary = c.GetControls(); foreach (PropertyInfo pi in properties) { foreach (string key in controlBinders.Keys) { string name = key + domainobject + pi.Name; if (!dictionary.ContainsKey(name)) continue; foreach (IControlBinder binder in controlBinders[key]) { binder.Bind(dictionary[name], GetValue(bindableObject, pi), pi, p); } } } }