public static void RegisterInsertDefaults(IDynamicDataSource dataSource, DetailsView detailsView, bool hideDefaults) { RequestContext requestContext = DynamicDataRouteHandler.GetRequestContext(HttpContext.Current); MetaTable table = dataSource.GetTable(); if (hideDefaults) { var fieldGenerator = detailsView.RowsGenerator as AdvancedFieldGenerator; if (fieldGenerator != null) { fieldGenerator.SkipList.AddRange(BuildSkipList(table, requestContext.RouteData.Values)); } else { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Expected a field generator of type {0}", typeof(AdvancedFieldGenerator).FullName)); } detailsView.ItemInserting += delegate(object sender, DetailsViewInsertEventArgs e) { SetDefaultInsertValues(table, requestContext.RouteData.Values, e.Values); }; } else { detailsView.DataBound += delegate(object sender, EventArgs e) { //In the seperate page version we pull the values from the querystring via routing SetDefaultInsertControlValues(table, detailsView, requestContext.RouteData.Values); }; } }
public static MetaTable FindMetaTable(this Control current) { // .NET doesn't perform the check, we will if (current == null) { throw new NullReferenceException(); } while (current != null) { DataBoundControl dbc = current as DataBoundControl; if (dbc != null) { IDynamicDataSource dds = dbc.DataSourceObject as IDynamicDataSource; if (dds != null) { return(dds.GetTable()); } } current = current.NamingContainer; } return(null); }
public void RegisterControl(Control control, bool setSelectionFromUrl) { // .NET doesn't check for null here, but since I don't like such code, we // will do the check and throw the same exception as .NET if (control == null) { throw new NullReferenceException(); } if (!ControlIsValid(control)) { throw new Exception("Controls of type " + control.GetType() + " are not supported."); } DataBoundControl dbc = control as DataBoundControl; if (dbc != null) { IDynamicDataSource dds = dbc.DataSourceObject as IDynamicDataSource; if (dds == null) { return; } MetaTable table = dds.GetTable(); if (table == null) { return; } GridView gv = control as GridView; if (gv != null) { gv.ColumnsGenerator = new AutoFieldGenerator(table); return; } } }
public void DynamicDataExtensions_GetTable_Test() { IDynamicDataSource dds = null; dds.GetTable(); }
public void RegisterControl(Control control, bool setSelectionFromUrl) { // .NET doesn't check for null here, but since I don't like such code, we // will do the check and throw the same exception as .NET if (control == null) { throw new NullReferenceException(); } if (!ControlIsValid(control)) { throw new Exception("Controls of type " + control.GetType() + " are not supported."); } // http://forums.asp.net/p/1257004/2339034.aspx // http://forums.asp.net/p/1383908/2936065.aspx DataBoundControl dbc = control as DataBoundControl; if (dbc != null) { IDynamicDataSource dds = dbc.DataSourceObject as IDynamicDataSource; if (dds == null) { return; } RegisterDataSource(dds); MetaTable table = dds.GetTable(); if (table == null) { return; } if (String.IsNullOrEmpty(dds.Where)) { dds.AutoGenerateWhereClause = true; } else { dds.AutoGenerateWhereClause = false; } Type contextType = dds.ContextType; if (contextType == null) { dds.ContextType = table.DataContextType; } string entityName = dds.EntitySetName; if (String.IsNullOrEmpty(entityName)) { dds.EntitySetName = table.DataContextPropertyName; } if (AutoLoadForeignKeys) { var ldds = dds as LinqDataSource; if (ldds != null) { ldds.LoadWithForeignKeys(table.EntityType); } } var gv = control as GridView; if (gv != null) { gv.ColumnsGenerator = new AutoFieldGenerator(table); return; } var dv = control as DetailsView; if (dv != null) { dv.RowsGenerator = new AutoFieldGenerator(table); return; } } }