/// <summary> /// Occurs when cell binds to the field value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnDataBindField(object sender, EventArgs e) { DataControlFieldCell cell = (DataControlFieldCell)sender; HyperLink link = (HyperLink)cell.Controls[0]; object controlContainer = cell.BindingContainer; object item = DataBinder.GetDataItem(controlContainer); // check if the complex type is used if (DataTextField.Length > 0 && DataContainer.Length > 0) { //string[] values = DataTextField.Split(new char[] { '.' }); item = DataBinder.Eval(item, this.DataContainer); if (item == null) { return; } } if (DataTextField.Length > 0) { if (dataTextFieldProperties == null) { SetupProperties(item); } object[] dataTextValues = new object[DataTextField.Split(',').Length]; for (int n = 0; n < dataTextValues.Length; n++) { dataTextValues[n] = dataTextFieldProperties[n].GetValue(item); } link.Text = FormatDataTextValue(dataTextValues); } string[] urlFields = DataNavigateUrlFields; if (urlFields.Length > 0) { if (urlProperties == null) { SetupProperties(item); } object[] dataUrlValues = new object[urlFields.Length]; for (int n = 0; n < dataUrlValues.Length; n++) { dataUrlValues[n] = urlProperties[n].GetValue(item); } link.NavigateUrl = FormatDataNavigateUrlValue(dataUrlValues); } }
public IEnumerable <TreeNode> SelectItems() { if (DataTextField.IsNullOrEmpty() || DataValueField.IsNullOrEmpty() || ParentField.IsNullOrEmpty()) { throw new FoxOneException("必须设置DataTextField、DataValueField和ParentField属性"); } var returnValue = new List <TreeNode>(); var dicts = GetList(); foreach (var dict in dicts) { returnValue.Add(new TreeNode() { Text = dict[DataTextField].ToString(), Value = dict[DataValueField].ToString(), ParentId = (dict.Keys.Contains(ParentField) && dict[ParentField] != null) ? dict[ParentField].ToString() : string.Empty }); } return(returnValue); }
/// <summary> /// Is used to set properties of the HyperLinkField /// </summary> /// <param name="controlContainer"></param> void SetupProperties(object controlContainer) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(controlContainer); if (DataTextField.Length > 0) { string[] dataFields = DataTextField.Split(','); if (dataFields.Length > 0) { dataTextFieldProperties = new PropertyDescriptor[dataFields.Length]; for (int n = 0; n < dataFields.Length; n++) { PropertyDescriptor prop = props[dataFields[n]]; if (prop == null) { throw new InvalidOperationException(string.Format("Property '{0}' not found in object of type {1}", dataFields[n], controlContainer.GetType())); } dataTextFieldProperties[n] = prop; } } } string[] urlFields = DataNavigateUrlFields; if (urlFields.Length > 0) { urlProperties = new PropertyDescriptor[urlFields.Length]; for (int n = 0; n < urlFields.Length; n++) { PropertyDescriptor prop = props[urlFields[n]]; if (prop == null) { throw new InvalidOperationException(string.Format("Property '{0}' not found in object of type {1}", urlFields[n], controlContainer.GetType())); } urlProperties[n] = prop; } } }
public override void WriteInitializationScript(TextWriter writer) { var options = new Dictionary <string, object>(Events); if (DataSource.Transport.Read.Url.HasValue()) { options["dataSource"] = DataSource.ToJson(); } else if (DataSource.Data != null) { options["dataSource"] = DataSource.Data; } if (DragAndDrop) { options["dragAndDrop"] = true; } if (AutoBind) { options["autoBind"] = true; } else { options["autoBind"] = false; } if (!LoadOnDemand) { options["loadOnDemand"] = false; } //else //{ // options["loadOnDemand"] = true; //} if (DataTextField.HasValue()) { options["dataTextField"] = DataTextField; } if (DataUrlField.HasValue()) { options["dataUrlField"] = DataUrlField; } if (DataSpriteCssClassField.HasValue()) { options["dataSpriteCssClassField"] = DataSpriteCssClassField; } if (DataImageUrlField.HasValue()) { options["dataImageUrlField"] = DataImageUrlField; } var idPrefix = "#"; if (IsInClientTemplate) { idPrefix = "\\" + idPrefix; } if (TemplateId.HasValue()) { options["template"] = new ClientHandlerDescriptor { HandlerName = string.Format("$('{0}{1}').html()", idPrefix, TemplateId) }; } else if (Template.HasValue()) { options["template"] = Template; } if (Checkboxes != null) { var checkboxes = Checkboxes.ToJson(); if (checkboxes.Keys.Any()) { options["checkboxes"] = checkboxes["checkboxes"]; } } //var animation = Animation.ToJson(); //if (animation.Keys.Any()) //{ // options["animation"] = animation["animation"]; //} writer.Write(Initializer.Initialize(Selector, "TreeView", options)); base.WriteInitializationScript(writer); }