/// <summary> /// Register a data control to give it Dynamic Data behavior /// </summary> /// <param name="setSelectionFromUrl">When true, if a primary key is found in the route values /// (typically on the query string), it will get be set as the selected item. This only applies /// to list controls.</param> public void RegisterControl(Control control, bool setSelectionFromUrl) { // if (DesignMode) { return; } IDataBoundControlInterface dataBoundControl = DataControlHelper.GetDataBoundControl(control, true /*failIfNotFound*/); // If we can't get an associated IDynamicDataSource, don't do anything IDynamicDataSource dataSource = dataBoundControl.DataSourceObject as IDynamicDataSource; if (dataSource == null) { return; } // If we can't get a MetaTable from the data source, don't do anything MetaTable table = MetaTableHelper.GetTableWithFullFallback(dataSource, Context.ToWrapper()); // Save the datasource so we can process its parameters in OnLoad. The value we set is irrelevant _dataSources[dataSource] = null; ((INamingContainer)control).SetMetaTable(table); BaseDataBoundControl baseDataBoundControl = control as BaseDataBoundControl; if (baseDataBoundControl != null) { EnablePersistedSelection(baseDataBoundControl, table); } RegisterControlInternal(dataBoundControl, dataSource, table, setSelectionFromUrl, Page.IsPostBack); }
/// <summary> /// See IWhereParametersProvider.GetWhereParameters /// </summary> public virtual IEnumerable <Parameter> GetWhereParameters(IDynamicDataSource dataSource) { var table = MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper()); // check makes no sense as the above call will throw //if (table == null) { // return new Parameter[0]; //} return(RouteParametersHelper.GetColumnParameters(table, Name)); }
public static MetaTable GetTable(this IDynamicDataSource dataSource) { return(MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper())); }
/// <summary> /// See IWhereParametersProvider.GetWhereParameters /// </summary> public virtual IEnumerable <Parameter> GetWhereParameters(IDynamicDataSource dataSource) { Debug.Assert(dataSource != null); // Find the control that the ControlParameter uses Control control = Misc.FindControl((Control)dataSource, ControlId); if (control == null) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, DynamicDataResources.DynamicControlParameter_DynamicDataSourceControlNotFound, ControlId)); } // If the control is itself a parameter provider, delegate to it var whereParametersProvider = control as IWhereParametersProvider; if (whereParametersProvider != null) { return(whereParametersProvider.GetWhereParameters(dataSource)); } IControlParameterTarget paramTarget = DynamicDataManager.GetControlParameterTarget(control); if (paramTarget == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicControlParameter_DynamicDataSourceControlCannotBeUsedAsParent, ControlId)); } string columnName = Name; MetaColumn column = null; MetaTable table = MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper()); if (!String.IsNullOrEmpty(columnName)) { column = table.GetColumn(columnName); } else { // There was no Name attribute telling us what field to filter, but maybe // the control given us data has that info column = paramTarget.FilteredColumn; } if (column == null) { // If there is no specific column, we're setting the primary key if (paramTarget.Table != table) { throw new Exception(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicControlParameter_InvalidPK, ControlId, paramTarget.Table, table.Name)); } return(GetPrimaryKeyControlWhereParameters(control, paramTarget)); } else if (column is MetaForeignKeyColumn) { return(GetForeignKeyControlWhereParameters(control, paramTarget, (MetaForeignKeyColumn)column)); } return(GetPropertyControlWhereParameters(control, paramTarget, column)); }