public void Initialize(FilterFields ff) { _filterFields = ff; _columnFilter = new ColumnFilter(); _columnFilter.FieldName = ff.FieldName; _columnFilter.ForeignField = ff.ForeignField; }
private static string BuildFilterVirtualPath(FilterFields ff) { string filterControlName = null; if (!String.IsNullOrEmpty(ff.FilterUIHint)) { filterControlName = ff.FilterUIHint; } filterControlName = filterControlName ?? GetDefaultFilterControlName(ff.FieldProp.PropertyType, ff.ModelName); return filterControlName; }
public static ScaffoldFilterUserControl CreateFilterControl(FilterFields ff) { if (ff == null) { throw new ArgumentNullException("FilterFields"); } string filterTemplatePath = GetFilterVirtualPath(ff); if (filterTemplatePath != null) { return (ScaffoldFilterUserControl)BuildManager.CreateInstanceFromVirtualPath(filterTemplatePath, typeof(ScaffoldFilterUserControl)); } return null; }
public static string GetFilterVirtualPath(FilterFields ff) { string filterControlName = BuildFilterVirtualPath(ff); return VirtualPathUtility.Combine(s_dynamicDataFolderVirtualPath, filterControlName + ".ascx"); }
public static ScaffoldFilterUserControl CreateUserControl(FilterFields ff) { return CreateFilterControl(ff); }
protected override void DataBind(bool raiseOnDataBinding) { ScaffoldingFilterRepeater.FilterRepeaterItem fri = (ScaffoldingFilterRepeater.FilterRepeaterItem)this.NamingContainer; _filterFields = null; if (fri is INamingContainer) { if (fri.DataItem is FilterFields) { _filterFields = (FilterFields)fri.DataItem; } } }
protected void Page_InitComplete(object sender, EventArgs e) { if (_initialized) { return; } int itemIndex = 0; if (_modelName != null && _modelName != String.Empty) { Type efModelType = Type.GetType(_modelName); if (efModelType != null) { foreach (PropertyInfo prop in efModelType.GetProperties()) { FilterFields ff = new FilterFields(); var filterUIAttribute = (FilterUIHintAttribute)prop.GetCustomAttribute(typeof(FilterUIHintAttribute), true); ff.FilterUIHint = String.Empty; ff.ForeignText = String.Empty; ff.SortField = String.Empty; ff.SortDescending = false; if (filterUIAttribute != null) { if (filterUIAttribute.FilterUIHint != String.Empty) { ff.FilterUIHint = GetFilterUIHintByName(filterUIAttribute.FilterUIHint); } else { ff.FilterUIHint = GetFilterUIHintByType(prop.GetType()); } if (ff.FilterUIHint != String.Empty) { var disAttribute = (DisplayAttribute)prop.GetCustomAttribute(typeof(DisplayAttribute), true); ff.DisplayName = ""; if (disAttribute == null) { var dnaAttribute = (DisplayNameAttribute)prop.GetCustomAttribute(typeof(DisplayNameAttribute), true); ff.DisplayName = dnaAttribute != null && !String.IsNullOrWhiteSpace(dnaAttribute.DisplayName) ? dnaAttribute.DisplayName : prop.Name; } else { ff.DisplayName = disAttribute != null && !String.IsNullOrWhiteSpace(disAttribute.Name) ? disAttribute.Name : prop.Name; } FilterRepeaterItem item = new FilterRepeaterItem() { DataItemIndex = itemIndex, DisplayIndex = itemIndex }; itemIndex++; ItemTemplate.InstantiateIn(item); Controls.Add(item); ScaffoldFilterControl filter = item.FindControl(ScaffoldFilterContainerId) as ScaffoldFilterControl; if (filter == null) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, "Could not find Control {1}, in template {0}, with ID {2}", ID, typeof(ScaffoldFilterUserControl).FullName, ScaffoldFilterContainerId)); } ff.FieldName = prop.Name; ff.ForeignField = ""; if (ff.FilterUIHint == ScaffoldConst.s_foreignKeyFilter) { ff.ForeignField = CheckForeignKeyName(efModelType, ff.FieldName); object cpTextDisplay = null; if (filterUIAttribute.ControlParameters.ContainsKey(ScaffoldConst.ForeignKey_TextField)) { cpTextDisplay = filterUIAttribute.ControlParameters[ScaffoldConst.ForeignKey_TextField]; } object cpSorting = null; if (filterUIAttribute.ControlParameters.ContainsKey(ScaffoldConst.ForeignKey_RequireSorting)) { cpSorting = filterUIAttribute.ControlParameters[ScaffoldConst.ForeignKey_RequireSorting]; } object cpDescendingOrder = null; if (filterUIAttribute.ControlParameters.ContainsKey(ScaffoldConst.ForeignKey_SortDesending)) { cpDescendingOrder = filterUIAttribute.ControlParameters[ScaffoldConst.ForeignKey_SortDesending]; } if (cpTextDisplay != null) { ff.ForeignText = cpTextDisplay.ToString(); } if (cpSorting != null) { ff.SortField = cpSorting.ToString(); } if (cpDescendingOrder != null) { ff.SortDescending = Convert.ToBoolean(cpDescendingOrder); } } ff.ModelName = _modelName; ff.FieldProp = prop; item.DataItem = ff; item.DataBind(); item.DataItem = null; _filters.Add(filter); } } } _filters.ForEach(f => f.Initialize()); _initialized = true; } else { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "{0} make sure its ModelName property contains a valid name of a EF Model within this project", ID)); } } else { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "{0} make sure its ModelName property contains a valid name of a EF Model within this project", ID)); } }